有谁知道这是在做什么:
if ! /fgallery/fgallery -v -j3 /images /usr/share/nginx/html/ "${GALLERY_TITLE:-Gallery}"; then
mkdir -p /usr/share/nginx/html
我理解第一部分是说如果 /fgallery/fgallery
目录不存在,但之后我就不清楚了。
最佳答案
在 Bash 中,我们可以这样构建一个基于命令退出状态的 if
:
if command; then
echo "Command succeeded"
else
echo "Command failed"
fi
then
部分在命令以 0 退出时执行,否则执行 else
部分。
您的代码正是这样做的。
可以重写为:
/fgallery/fgallery -v -j3 /images /usr/share/nginx/html/ "${GALLERY_TITLE:-Gallery}"; fgallery_status=$?
if [ "$fgallery_status" -ne 0 ]; then
mkdir -p /usr/share/nginx/html
fi
但前一种构造更优雅且不易出错。
查看这些帖子:
关于bash - 了解调用命令的 Bash if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44033274/