Bash 中的 if Not 条件
作者:迹忆客
最近更新:2023/03/17
浏览次数:
在 bash 中,如果命令列表的代码为真,那么 if | then
语句在单词 then
之后执行一个或多个命令。如果检查返回 false,则在条件需要时执行 else
。我们将在这里学习制作如果不是
条件。
Bash 中整数情况下的 if not
条件
我们可以使用 -ne
来检查两个整数变量之间的不等式。让我们看一个例子。
#!/bin/bash
x=5
y=4
if [[ $x -ne $y ]];
then
echo "Not equal"
fi
输出:
Not equal
Bash 中字符串的 if not
条件
我们可以使用 !=
运算符来比较两个字符串。
#!/bin/bash
sone=Bin
stwo=Bash
if [[ $sone != $stwo ]];
then
echo "Not equal"
fi
输出:
Not equal
表达式中的 Bash if not
条件
我们可以使用!
[[]]
之外的运算符使整个表达式的输出为负数。我们不能在双方括号内进行操作以使单个表达式为负数。让我们看一个例子。
#!/bin/bash
n=4
if ! [[ $n -eq 0 ]];
then
echo "Not equal to 0"
fi
输出:
Not equal to 0
相关文章
在 Bash 中运行 find -exec 命令
发布时间:2024/03/14 浏览次数:127 分类:操作系统
-
本文将演示如何使用 find 命令的 -exec 参数来使用 find 命令定位文件中的任何文本。