作用:去掉文件的目录和后缀
1.去掉文件路径
1 [email protected]:~/ci/script$ basename /backup/jenkins/ci/script/Release.sh.bak 2 Release.sh.bak
2.去掉文件后缀
1 [email protected]:~/ci/script$ basename /backup/jenkins/ci/script/Release.sh.bak .bak 2 Release.sh 3 [email protected]:~/ci/script$ ls 4 Release.sh Release.sh.bak 5 [email protected]:~/ci/script$
3.考虑后缀数量
[email protected]:~/ci/script$ basename /backup/jenkins/ci/script/Release.sh.bak.old .old Release.sh.bak [email protected]:~/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 [email protected]:~/ci/script$ basename ab b 2 a
5.其他
[email protected]—— 打印参数
$#—— 打印参数个数
$?—— 最后一个命令/函数的执行结果,0为成功,非0失败
$!—— 最后一个后台运行进程的PID
$$—— 最后一个后台运行进程的PPID
时间: 2024-10-12 07:47:52