我想了解-e /sudoers.tmp -o "$(pidof visudo)"
在以下代码段中的作用。
#!/bin/bash
if [ -e /etc/sudoers.tmp -o "$(pidof visudo)" ]; then
echo "/etc/sudoers busy, try again later"
exit 1
fi
cp /etc/sudoers /etc/sudoers.bak
cp /etc/sudoers /etc/sudoers.tmp
chmod 0640 /etc/sudoers.tmp
echo "whatever" >> /etc/sudoers.tmp
chmod 0440 /etc/sudoers.tmp
mv /etc/sudoers.tmp /etc/sudoers
exit 0
欣赏有关该特定条件的详细说明。
答案 0 :(得分:4)
此:
if [ -e /etc/sudoers.tmp -o "$(pidof visudo)" ]; then
正在使用test
命令。要查看-e
测试的作用,您可以运行help test
并查看输出:
Evaluate conditional expression.
Exits with a status of 0 (true) or 1 (false) depending on
the evaluation of EXPR. Expressions may be unary or binary. Unary
expressions are often used to examine the status of a file. There
are string operators and numeric comparison operators as well.
The behavior of test depends on the number of arguments. Read the
bash manual page for the complete specification.
File operators:
[...]
-e FILE True if file exists.
因此,-e /etc/sudoers.tmp
正在检查该文件是否存在。
答案 1 :(得分:1)
[ -e /etc/sudoers.tmp -o "$(pidof visudo)" ]
表示文件/etc/sudoers.tmp
存在或命令pidof visudo
的返回状态不为0,表示visudo
正在运行。