这里检查的 if [[ -z $1 ]]
语句到底是什么?
每当我运行时,它都会输出如下:
[root@localhost ~]# sh script.sh
No argument is given
#!/bin/bash
if [[ -z $1 ]]; then
echo "No argument is given"
elif [ "$1" == "testfile" ] ; then
echo "Right argument is given"
else
echo "Wrong argument is given"
fi
最佳答案
参见man bash
:
[[ expression ]]
Return a status of 0 or 1 depending on the evaluation of the conditional expression
以及下文
-z string
True if the length of string is zero.
关于linux - 在 bash 脚本中使用它。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44977889/