If and else statement using diff -q
7,631
- You don't put diff in brackets
- 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
Related videos on Youtube
Author by
Gui Montag
Updated on September 18, 2022Comments
-
Gui Montag almost 2 years
So I'm trying to write an if else statement which involves the use of
diff -q
. So, let's say I have two fileshi.txt
andhello.txt
and I store them into variables called hi and hello respectively. I have this piece of codeif [ 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
andhello.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?
-
Alessio over 8 yearsif the answer works for you, don't just say thanks - accept it. meta.stackexchange.com/questions/23138/…