linux - While 语句有助于 bash 脚本编写

标签 linux bash scripting

需要帮助理解这个脚本,我不明白-z是什么条件意味着第一行然后 -z"$1"在 if 语句中 这是脚本:

while [ -z "$USERNAME" ]
do
if [ -z "$1" ]
    then
        unset ans
 unset USER
 echo "What is the username you would like to add?"
 read USER
 echo "Is" $USER " the correct username? [y/n]"
 read ans
 case "$ans" in
     y|Y|yes|Yes|YES)
  USERNAME=$USER

;;

最佳答案

-z
string is null, that is, has zero length

有关 test 的完整信息在bash中

请参阅special variables了解有关 $1 的更多信息。

Arguments passed to the script from the command line [1] : $0, $1, $2, $3 . . .

$0 is the name of the script itself, $1 is the first argument

关于linux - While 语句有助于 bash 脚本编写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48695087/

相关文章:

Linux:在脚本中运行二进制文件

linux - 图像转换和Inode使用

bash - 如何将文件中的行从最短到最长排序?

macos - Mac终端错误-bash : command not found - El Capitan 10. 11.13

linux - 查看启动时运行的文件 (linux)

c# - 使用 EnvDTE.ExecuteCommand 以编程方式开始调试特定项目

mysql - 覆盖sql表结构

linux - 磁盘已满,但找不到哪个文件夹占用空间

linux - 如何使用 linux 命令交换重复格式数据 block 内的数字?

linux - 将 ffmpeg 结果重定向到另一个文件