需要检查输入参数Mac上的Bash Shell脚本

Mor*_*ive 2 macos bash terminal

我想检查OSX上bash脚本上输入参数的存在性。我做:

if [-z "$1"]
Run Code Online (Sandbox Code Playgroud)

我得到:

/usr/local/bin/deploy.sh: line 8: [-z: command not found
Run Code Online (Sandbox Code Playgroud)

有小费吗?

谢谢。

P.P*_*.P. 6

您需要在条件周围留一个空格:

if [ -z "$1" ]

    ^       ^
Run Code Online (Sandbox Code Playgroud)