2

So I'm trying to write an if else statement which involves the use of diff -q. So, let's say I have two files hi.txt and hello.txt and I store them into variables called hi and hello respectively. I have this piece of code

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

No matter what hi.txt and hello.txt contain, even if they have exactly the same content. I get an error saying

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

What part of my syntax is wrong?

0

1 Answer 1

8
  1. You don't put diff in brackets
  2. The Syntax to use variable is $hi

so the resulting script is:

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.