我怎样才能在 bash 中做这样的事情?
if "`command` returns any error";
then
echo "Returned an error"
else
echo "Proceed..."
fi
Run Code Online (Sandbox Code Playgroud) 我对这些运算符在 bash 中使用时有何不同(括号、双括号、括号和双括号)感到有些困惑。
[[ , [ , ( , ((
Run Code Online (Sandbox Code Playgroud)
我见过人们在这样的 if 语句中使用它们:
if [[condition]]
if [condition]
if ((condition))
if (condition)
Run Code Online (Sandbox Code Playgroud) 我总是惊讶于文件夹中/bin有一个[程序。
这就是我们在做这样的事情时所说的:if [ something ]?
通过[在 shell 中显式调用程序,它会要求提供相应的],并且当我提供右括号时,无论我在括号之间插入什么,它似乎什么都不做。
毋庸置疑,获得有关程序帮助的通常方法是行不通的,即既不可行man [也不行[ --help。
我的文件中有一小节.bashrc我不明白,我想问一下它的含义和一些语法解释。
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Run Code Online (Sandbox Code Playgroud)
我当然明白 # 使每一行都成为注释。
你能给我解释一下这个if ... then声明吗?什么-f意思?
为什么[]代码的第一行有这些?
;为什么后面有[ -f ~/.bash_aliases ]?
为什么代码的第二行以 a 开头,.以及整个第二行的实际含义。我知道.bash_aliasesLinux 中包含 bash_aliases 的文件,但我不明白第二行。