a) command1의 출력은
output=$(diff "helloworld$x.out" "output/helloworld$x.out")
또는 백틱을 사용하지만 중첩 할 수 없기 때문에 권장하지 않으며 글꼴에 따라 아포스트로피와 구분하기가 어려울 수 있습니다.
output=`cmd1`
b) 파일에 쓴 다음 해당 파일을 읽거나 출력을 잡아서 에코하는 대신 파이프를 직접 사용합니다.
cmd1 > file
cat file | cmd2
output=$(cmd1)
echo "${output}" | cmd2
=>
cmd1 | cmd2
그러나 귀하의 예에서는 출력에 관심이 없지만 프로그램의 결과는 효과가 있습니까?
diff "helloworld$x.out" "output/helloworld$x.out" && echo "success" || echo "failure"
&& 및 ||의 사용법에 대해 읽으려면 "바로 가기 AND 및 바로 가기 OR"을 검색하십시오.
출력을 깨끗하게 유지하려면 'diff'의 출력을 다른 곳으로 리디렉션 할 수 있습니다.
diff "helloworld$x.out" "output/helloworld$x.out" >/dev/null && echo "success" || echo "failure"
성공 여부를 나중에 평가하려면 마지막 명령의 결과를 $?와 함께 변수에 저장하십시오.
diff "helloworld$x.out" "output/helloworld$x.out" >/dev/null
result=$?
# do something else
case $result in
0) echo success ;;
*) echo failure ;;
esac
... > /dev/null이 맥락에서 무엇을하는지 이해하지 못합니다 . diff의 출력은 / dev / null로 이동하지만 아무것도 아닙니다.