![상태 코드로 스크립트를 종료하려고 하는데 "예기치 않은 파일 끝" 메시지가 나타납니다.](https://linux55.com/image/110066/%EC%83%81%ED%83%9C%20%EC%BD%94%EB%93%9C%EB%A1%9C%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EB%A5%BC%20%EC%A2%85%EB%A3%8C%ED%95%98%EB%A0%A4%EA%B3%A0%20%ED%95%98%EB%8A%94%EB%8D%B0%20%22%EC%98%88%EA%B8%B0%EC%B9%98%20%EC%95%8A%EC%9D%80%20%ED%8C%8C%EC%9D%BC%20%EB%81%9D%22%20%EB%A9%94%EC%8B%9C%EC%A7%80%EA%B0%80%20%EB%82%98%ED%83%80%EB%82%A9%EB%8B%88%EB%8B%A4..png)
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
실행하면 마지막 두 개의 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과 동일한 것으로 처리됩니다( !=
다른 것으로 간주됨).