作用:去掉文件的目录和后缀
1.去掉文件路径
1 jenkins@work:~/ci/script$ basename /backup/jenkins/ci/script/Release.sh.bak 2 Release.sh.bak
2.去掉文件后缀
1 jenkins@work:~/ci/script$ basename /backup/jenkins/ci/script/Release.sh.bak .bak 2 Release.sh 3 jenkins@work:~/ci/script$ ls 4 Release.sh Release.sh.bak 5 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.不正常的后缀
1 jenkins@work:~/ci/script$ basename ab b 2 a
5.其他
$@—— 打印参数
$#—— 打印参数个数
$?—— 最后一个命令/函数的执行结果,0为成功,非0失败
$!—— 最后一个后台运行进程的PID
$$—— 最后一个后台运行进程的PPID