local var=""
if [ -z "$var" ]; then
echo "\$var is empty"
else
echo "\$var is NOT empty"
fi
if [ -n "$1" ]; then
echo "You supplied the first parameter!"
else
echo "First parameter not supplied."
fi
可以使用非运算符-!
, 如
if [[ ! -z "$var" ]]; then
echo "\$var is NOT empty"
fi
- 判断文件是否存在
if [[ -f "$file" ]]; then
echo "File - $file exists"
else
echo "File - $file does not exist"
fi
if [[ -L "$file" ]]; then
echo "File - $file is symbolic link"
fi
读取符号链接所对应的真实文件名
local _uname="$(uname -s)"
if [[ "${_uname}" == "Darwin" ]]
then
filepath="$(greadlink -f "$FILE")"
else
filepath="$(readlink -f "$FILE")"
fi
FILE=/etc/docker
if [ -d "$FILE" ]; then
echo "$FILE is a directory"
fi
- 级联创建目录仅当其不存在的情况下
mkdir -p [/path/to/my/dir]
TODO