linux - 在 bash 脚本中使用它。

标签 linux bash shell

这里检查的 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/

相关文章:

bash - 使用 find 删除所有子目录(及其文件)

windows - 在 Windows Shell 中将包含 *(星号)字符的字符串作为命令行参数传递

linux - 更改目录中具有 csv 扩展名的文件名

linux - 阻止其他用户访问我的主目录中的特定目录?

xml - 为什么计数节点不起作用?

linux - 以下命令中-print0的含义是什么

linux - 为什么在我的 .bashrc 中使用 `uname` 时出现错误?

bash - 将光标移回 shell 脚本中的第一列

linux - 如何在Linux中使用一个命令的输出作为另一命令

java - 如何忽略 Subversion 中的目录/文件?