A few points:
- process substitution (
<( ... )) and the extended test syntax[[ ... ]]is not available in sh. You need more advanced shells like bash or ksh for those. $(( ... ))is arithmetic substitution, not command substitution. You need$( ... )here.- Instead of checking the output of
diff, you can check the exit status ofdiffdirectly in theifcondition. You can discard the unused output. (So you don't even need command substitution or[[ ... ]]here.)
And suggestions from the comments:
- You can avoid negating the condition in
ifby swapping theifandelseblocks - You can use the just-as-efficient
cmp -scommand if all you want to do is check if the files are different.
Combined:
#!/bin/bash
if ! diffcmp -qs <(sort 1.txt) <(sort 2.txt) > /dev/null
then
echo ERRORPASS
else
echo PASSERROR
fi