
Amazon Linuxでbashシェルを使用しています。私のスクリプトが構文エラーのためにクラッシュする理由を理解できません。私のスクリプトはこれで終わります
chmod 775 $TFILE2
output_file=$( create_test_results_file "$TFILE2" )
(cat $TFILE2; uuencode $output_file $output_file) | mailx -s "$subject" "$to_email"
rm $output_file
echo "sent second email"
#Cleanup
rm $TFILE1
rm $TFILE2
echo "removed files"
# If node exited unsuccessfully, verify we alert the process above.
if [ $rc1 != 0 ]; then exit $rc1 fi
if [ $rc2 != 0 ]; then exit $rc2 fi
実行すると、最後の2つのechoステートメントが印刷されますが、それ以降は死ぬようです。
sent second email
removed files
/home/jboss/.jenkins/jobs/springboard/workspace/automated-tests/nodejs/run_tests.sh: line 86: syntax error: unexpected end of file
予期しないファイル終了エラーが原因で終了した理由を知らせる人はいますか?
答え1
つまり、fi
別のコマンドが必要なので、セミコロンが必要です。
if [ $rc1 != 0 ]; then exit $rc1; fi
if [ $rc2 != 0 ]; then exit $rc2; fi
変数を引用する必要があり、整数を比較しているので、適切な演算子を使用してください。
if [ "$rc1" -ne 0 ]; then exit "$rc1"; fi
if [ "$rc2" -ne 0 ]; then exit "$rc2"; fi
ここでの動作は少し異なりますが、null値は0と同じものとして扱われます(!=
他と見なされます)。