Shell

從 qingwei personal wiki
跳到: 導覽搜尋

提取文件/目錄

提取文件名

  • 不包含後綴
# 不包含后缀
${var%%.*}
# 该命令的使用是去掉变量var从右边算起的最后一个'.'字符及其右边的内容,返回从右边算起的最后一个'.'(不含该字符)的左边的内容

# 例子
[qingwyan@localhost ~]$ aaaa=1.text
[qingwyan@localhost ~]$ echo ${aaaa##*.}
text
[qingwyan@localhost ~]$ test=/root/qingwyan.txt
[qingwyan@localhost ~]$ echo ${test%%.*}
/root/qingwyan