basename usage in linux

作用:去掉文件的目录和后缀

1.去掉文件路径

 jenkins@work:~/ci/script$ basename /backup/jenkins/ci/script/Release.sh.bak
Release.sh.bak

2.去掉文件后缀

 jenkins@work:~/ci/script$ basename /backup/jenkins/ci/script/Release.sh.bak .bak
Release.sh
jenkins@work:~/ci/script$ ls
Release.sh Release.sh.bak
jenkins@work:~/ci/script$

3.考虑后缀数量

jenkins@work:~/ci/script$ basename /backup/jenkins/ci/script/Release.sh.bak.old .old
Release.sh.bak
jenkins@work:~/ci/script$ basename /backup/jenkins/ci/script/Release.sh.bak.old .old .bak
basename: extra operand `.bak'
Try `basename --help' for more information.

4.不正常的后缀

 jenkins@work:~/ci/script$ basename ab b
a

5.其他

$@—— 打印参数

$#—— 打印参数个数

$?—— 最后一个命令/函数的执行结果,0为成功,非0失败

$!—— 最后一个后台运行进程的PID

$$—— 最后一个后台运行进程的PPID

上一篇:ajax中的application/x-www-form-urlencoded中的使用


下一篇:yii 简单依赖注入