simplycoding
simplycoding

Reputation: 2977

Bash giving message that there are too many arguments when if statement is continued onto newline

I have a long if clause in my Bash script that is giving me a warning of script.sh: line 1: [: too many arguments

Here is the if clause:

if [ ! -f first_"$today".csv.gz ] || [ ! -f second_"$today".csv.gz ] || [ ! -f third_"$today".csv.gz ] || [ ! -f fourth_"$today".csv.gz ] || [ ! -f fifth_"$today".csv.gz ] || [ ! -f sixth_"$today".csv.gz ]\
   [ ! -s first_"$today".csv.gz ] || [ ! -s second_"$today".csv.gz ] || [ ! -s third_"$today".csv.gz ] || [ ! -s fourth_"$today".csv.gz ] || [ ! -s fifth_"$today".csv.gz ] || [ ! -s sixth_"$today".csv.gz ];

So I worked backwards by commenting out each if bracket/statement from the end. When I ended up commenting out the entire second line and ending the if clause at the end of the first line, I stopped receiving the error/warning message. I have similar if statements elsewhere in my script, and they all run perfectly fine.

My script does not break at all, as it continues on with the rest of the script. I would like to fix this so that the warning message stops popping up. Is there something I'm doing wrong with the newline character? Anything else I missed?

Upvotes: 1

Views: 28

Answers (1)

Karoly Horvath
Karoly Horvath

Reputation: 96266

The operator (||) is missing where you break the line.

Upvotes: 3

Related Questions