I'm not understanding why the diff
command is not working correctly in my script. Can anybody clarify it for me?
Here is the bash script:
#!/bin/bash
SRC="src-folder"
DST="dst-folder"
FILES=( a/ b/ c/ )
for f in ${FILES[@]}; do
cmd="diff -q $SRC/$f $DST/$f"
echo $cmd # row-9
$cmd # row-10
done
Script output seems like this:
diff -q src-folder/a/ dst-folder/a/
diff -q src-folder/a/ dst-folder/a/
diff -q src-folder/a/ dst-folder/a/
diff -q src-folder/a/ dst-folder/a/
diff -q src-folder/a/ dst-folder/a/
diff -q src-folder/a/ dst-folder/a/
diff -q src-folder/a/ dst-folder/a/
(until buffer overflow)
When I disable/remove/comment row-10 I can see correct output (when I run these commands in an interactive shell rather than in the script I get correct results):
diff -q src-folder/a/ dst-folder/a/
diff -q src-folder/b/ dst-folder/b/
diff -q src-folder/c/ dst-folder/c/
When I change diff
to rsync
, everything is working correctly (call from script).
So how can I use diff
in scripts? What's the reason that diff
called by my script is not working as expected?
I tried also a very simple script:
#!/bin/bash
diff -q src-folder/a dst-folder/a
diff -q src-folder/b dst-folder/b
But it doesn't work. When I change diff
command to any other (e.g. rsync
), everything is working.