正则表达式
采用 [[ $1 =~ $reg ]] 可以检查 $1 是否符合正则表达式 $reg:
#!/bin/zshif [[ $1 =~ .*\.html$ ]]thenecho "$1 is html"elseecho "$1 is not html"fi
这段代码判断输入参数是否是以 html 结尾的字符串。
$ ./htmlcheck.zsh hello.html
输出:
hello.html is html
判断文件是否存在
使用 -f 判断文件是否存在。
#!/bin/zshif [ -f $1 ]thenecho "$1 exist"elseecho "$1 does not exist"fi
用法:
$ ./check.zsh hello.html
