Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmp in if statement (Bash) [duplicate]

if [ cmp -s "$expectedOut" "$actualOut" ]; then

The following line of code keeps giving me errors saying that there are too many arguments. however I know this is the proper typical use of cmp so I think it may have to do with the brackets. Anyone know whats really going on here?

like image 718
cosmicluna Avatar asked Sep 18 '25 03:09

cosmicluna


1 Answers

Lose the [ ].

if cmp -s "$expectedOut" "$actualOut" ; then

The syntax of if is

if Command; then

[ is just one possible command (on that happens to expect ] as its last argument to make things look pretty).

like image 120
PSkocik Avatar answered Sep 20 '25 15:09

PSkocik