Home  >  Q&A  >  body text

linux - Bash语法中的`-z`是什么意思?

尝试模仿spf13-vim.sh这个脚本写一个脚本时;看到其中有如下代码片段:

############################  SETUP PARAMETERS
app_name='spf13-vim'
[ -z "$APP_PATH" ] && APP_PATH="$HOME/.spf13-vim-3"
[ -z "$REPO_URI" ] && REPO_URI='https://github.com/spf13/spf13-vim.git'
[ -z "$REPO_BRANCH" ] && REPO_BRANCH='3.0'
debug_mode='0'
fork_maintainer='0'
[ -z "$VUNDLE_URI" ] && VUNDLE_URI="https://github.com/gmarik/vundle.git"

看到其中[ -z "$APP_PATH" ] && APP_PATH="$HOME/.spf13-vim-3"类似这句话,google查阅理解如下:
如果不存在APP_PATH这个变量,就把APP_PATH的值设置为"$HOME/.spf13-vim-3"。不知道是不是正确的?
-z这个变量我google搜索没有找到我需要的结果相关结果(亦或者有相关搜索方法吗?)


分割线

如果要知道这个命令的含义,直接在Terminal输入man [就可以看到帮助了,感谢@
springhack 的回答。

迷茫迷茫2744 days ago1161

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-17 15:48:53

    First of all, you should check the help of [command;
    Secondly, it is used to determine whether the string length is 0 (Zero)

    reply
    0
  • 迷茫

    迷茫2017-04-17 15:48:53

    That’s a judgment expression, there are several ways to write it

    It is recommended to go through the shell syntax systematically first

    Shell has a lot of pitfalls, otherwise if you imitate it like this, the shell you write in the future will have problems

    reply
    0
  • Cancelreply