![특정 명령이 성공했는지 확인하는 방법이 있습니까?](https://linux55.com/image/96281/%ED%8A%B9%EC%A0%95%20%EB%AA%85%EB%A0%B9%EC%9D%B4%20%EC%84%B1%EA%B3%B5%ED%96%88%EB%8A%94%EC%A7%80%20%ED%99%95%EC%9D%B8%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%B4%20%EC%9E%88%EC%8A%B5%EB%8B%88%EA%B9%8C%3F.png)
이것이 이전 명령의 상태를 제공한다는 것을 알고 있지만 $?
특정 명령의 상태를 어떻게 얻을 수 있습니까?
rsync -avh -r /Source/ /Destination/
folderParam=$(basename !:3)
//commandResultvar : here I want to store status of rsync command
답변1
rsync -avh -r /Source/ /Destination/
rsync_status=$?
folderParam=$(basename !:3)
# use ${rsync_status} here...
답변2
특정 명령에서 종료 코드를 가져올 수 없습니다. 이전 것에서만 얻을 수 있습니다. 하지만 이 값을 다른 변수에 저장하고 나중에 사용하는 것을 방해하는 것은 없습니다.
rsync -avh -r /Source/ /Destination/
EXIT_CODE=$?
folderParam=$(basename !:3)
# $EXIT_CODE contains the exit code of the rsync command