我在一堆帐户上运行 offlineimap,并希望检查每次运行的退出代码并相应地执行一些操作。
我有 6 个独立的电子邮件帐户,我使用大量重复代码运行这些帐户。原来的命令结构是:
$ $(which offlineimap) -c offlineimaprc -o -a yahoo & declare yahoo_pid=$!
wait $yahoo_pid
yahoo_st=$?
if [[ $yahoo_st -ne 0 ]];then <do some stuff>
$ $(which offlineimap) -c offlineimaprc -o -a gmail & declare gmail_pid=$!
wait $gmail_pid
gmail_st=$?
if [[ $gmail_st -ne 0 ]];then <do some stuff>
现在我想删除重复项并从for in
循环和wait
命令中运行它。${account-name}_pid(例如 yahoo_pid)替换工作正常,但我被命令卡住了wait
。
$ for app in yahoo gmail
do
$(which offlineimap) -c offlineimaprc -o -a ${app} & declare ${app/%/_pid}=$!
wait ${app}_pid
done
[1] 73443
-bash: wait: `$yahoo_pid': not a pid or valid job spec
[2] 73444
-bash: wait: `$gmail_pid': not a pid or valid job spec