【发布时间】:2017-02-12 12:30:36
【问题描述】:
我是脚本新手,想了解如何根据布尔逻辑打印出变量。
#!/bin/bash
# set variables
WEBAPPS_YES="Successfully synced webapps folder"
WEBAPPS_NO="Could not sync webapps folder"
RSYNC_YES="Successfully synced rsync log file"
RSYNC_NO="Could not sync rsync log file"
# Command to rsync 'webapps' folder and write to a log file
rsync -azvh ~/webapps -e ssh user@something.com:/home/directories >> /path/to/rsync.log 2>&1
# Command to rsync 'rsync.log' to a log file on backup server 'Larry'
rsync -azvh --delete ~/rsync.log -e ssh user@something.com:/path/to/logs
if [ $? -eq 0 ]
then
echo
exit 0
else
echo >&2
exit 1
fi
如果两个部分都成功与否,我希望将整个 if、then、else 部分打印在 echo 中。我知道我需要某种逻辑语句,但无法弄清楚。
【问题讨论】:
标签: bash if-statement boolean-expression error-code