我试图理解bash环境中的复合列表以及列表末尾的布尔返回值是什么,但我还没有找到完整的答案。
此处给出的复合列表的定义给出了 while 循环中复合列表的示例:
while
# a couple of <newline>s
# a list
date && who || ls; cat file
# a couple of <newline>s
# another list
wc file > output & true
do
# 2 lists
ls
cat file
done
但我不太明白条件 - while 循环是否仅在列表中的所有条件都为真时才执行?或者只有当最后一个条件为真时才为真?一个更简单的例子可能如下:
if
condition1
condition2
then
command1
fi
command1
是否仅在条件2为真时才执行,或者条件1和&条件2都必须为真才能执行,即:
if
condition1 && \
condition2
then
command1
fi
while date && who || ls; cat file; wc file > output & true
do
ls
cat file
done
我能说的最好的,因为它是无稽之谈,相当于:
foo() {
date; rc=$?
if $rc
then
who; rc=$?
fi
if ! $rc
then
ls
fi
cat file
wc file > output &
return true
}
while foo
do
ls
cat file
done
希望有帮助。