我对'if ... then ... fi'和'for'语句语法有点不熟悉。Bash - if和for语句
任何人都可以解释下面代码片段中的“$ 2/$ fn”和“/ etc/* release”是什么意思?......特别是使用正斜杠....和星号.. 。
if [ -f "$filename" ]; then
if [ ! -f "$2/$fn" ]; then
echo "$fn is missing from $2"
missing=$((missing + 1))
fi
fi
和
function system_info
{
if ls /etc/*release 1>/dev/null 2>&1; then
echo "<h2>System release info</h2>"
echo "<pre>"
for i in /etc/*release; do
# Since we can't be sure of the
# length of the file, only
# display the first line.
head -n 1 $i
done
uname -orp
echo "</pre>"
fi
} # end of system_info
... THX的帮助...
使用'ls'来测试文件的存在是丑陋和脆弱的。不幸的是,编码的正确方式有点依赖于你的shell。这个特定的嵌套循环可能会被压缩为一个循环,如果glob上没有匹配(即,如果/ etc/* release'不匹配任何文件),该循环就不会执行。 – tripleee