Bash: if and typecheck
This question already has an answer here:
使用case语句。
case "$file" in
*.txt) emacs $file ;;
*.zip) zip $file ;;
esac
You can either use:
if [ ${file: -4} == ".txt" ]
and thus compare the last 4 characters
Or use:
if [[ $file == *.txt ]]
and thus use a regular expression (double brackets are available only in some shells but it is available in bash
).
上一篇: 如何在查找FOR循环时从名称中删除扩展名
下一篇: Bash:如果和typecheck