Chinaunix首页 | 论坛 | 博客
  • 博客访问: 167695
  • 博文数量: 41
  • 博客积分: 445
  • 博客等级: 下士
  • 技术积分: 280
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-22 14:54
文章分类

全部博文(41)

文章存档

2015年(9)

2014年(7)

2013年(4)

2012年(21)

我的朋友

分类:

2015-01-28 15:17:24

原文地址:关于shell中的basename 作者:jennyljd

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

另一种实现的方法:
${var##*/} 就是把变量var最后一个/以及左边的内容去掉
${var%/*} 就是把变量var最后一个/以及右边的内容去掉
阅读(1182) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~