码迷,mamicode.com
首页 > 系统相关 > 详细

shell中的basename dirname read

时间:2014-12-07 12:37:19      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:style   ar   color   sp   strong   on   bs   ad   amp   

1. basename 是去除目录后剩下的名字
example:shell>temp=/home/temp/1.test
         shell>base=`basename $temp`
         shell>echo $base
结果为:1.test
2. dirname 是取目录
example:shell>temp=/home/temp/1.test
         shell>dir=`dirname $temp`
         shell>echo $dir
结果为:/home/temp

另一种实现的方法
${var##*/} 就是把变量var最后一个/以及左边的内容去掉

${var%/*} 就是把变量var最后一个/以及右边的内容去掉

3.read

#!/bin/bash
echo -n "Enter your name:"   //参数-n的作用是不换行,echo默认是换行
read  name                   //从键盘输入
echo "hello $name,welcome to my program"     //显示信息
exit 0                       //退出shell程序。
//********************************
由于read命令提供了-p参数,允许在read命令行中直接指定一个提示。
所以上面的脚本可以简写成下面的脚本::
#!/bin/bash
read -p "Enter your name:" name
echo "hello $name, welcome to my program"
exit 0


shell中的basename dirname read

标签:style   ar   color   sp   strong   on   bs   ad   amp   

原文地址:http://blog.csdn.net/chun_1959/article/details/41786533

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!