diff -q를 사용하는 If 및 else 문

diff -q를 사용하는 If 및 else 문

그래서 저는 를 사용하는 if else 문을 작성하려고 합니다 . 두 개의 파일이 있고 이를 hi 및 hello라는 변수에 저장한다고 diff -q가정해 보겠습니다 . 이 코드가 있습니다hi.txthello.txt

if [ diff -q $hi $hello ]; then
  echo "these files are the same"
else 
  echo "these files are not the same"
fi

포함된 내용이 무엇이든 hi.txt, hello.txt내용이 완전히 동일하더라도 마찬가지입니다. 오류 메시지가 나타납니다.

./(name of script) line (line with [diff -q hi hello]) [: too many arguments. 

내 문법의 어떤 부분이 잘못됐나요?

답변1

  1. 괄호 안에 diff를 넣지 않았군요
  2. 변수를 사용하는 구문은 다음과 같습니다.$hi

따라서 생성된 스크립트는 다음과 같습니다.

if diff -q $hi $hello; then
echo "these files are the same"
else
echo "these files are not the same"
fi

관련 정보