我正在搞rsync腳本來同步一些東西到我的手機。我試圖編寫一個if語句來決定在命令完成時我在電子郵件中收到哪條消息。出於某種原因,無論命令如何退出,我都會收到兩封電子郵件。爲什麼這個bash「if」語句執行兩條語句
success_message=echo "Podcasts are synced." | mail -s "Your podcasts have been synced to your phone." $email_address
fail_message=echo "Your phone did not sync." | mail -s "For some reason, your podcasts did not sync today." $email_address
rsync --log-file=/home/jake/logs/rsync.log -avzu $local_directory $remote_directory
if [ $? -ne "0" ];
then
$fail_message
else
$success_message
fi
更好適應上unix.stackexchange.com? –
這不是你如何有條件地運行命令。完全一樣。 –
甚至在進入rsync之前,您的'mail'命令正在執行。 – lurker