更新时间:2022-03-14 22:39:55
有很多方法可以做到这一点。您可以在双括号中使用通配符:
str="/some/directory/file"
if [[ $str == /* ]]; then echo 1; else echo 0; fi
您可以使用子字符串扩展:
if [[ ${str:0:1} == "/" ]] ; then echo 1; else echo 0; fi
或正则表达式:
if [[ $str =~ ^/ ]]; then echo 1; else echo 0; fi