Bash: Too Many Arguments

I encoded the following script to add users from a text file. It works, but I get the error "too many arguments"; what is the problem?

#!/bin/bash file=users.csv while IFS="," read USRNM DOB SCH PRG PST ENROLSTAT ; do if [ $ENROLSTAT == Complete ] ; then useradd $USRNM -p $DOB else echo "User $USRNM is not fully enrolled" fi done < $file #cat users.csv | head -n 2 | tail -n 1 
+4
source share
1 answer

Use quotation marks. Plentifully.

 if [ "$ENROLSTAT" = Complete ] 

(This is also an equal sign). My biggest problem in shell programming is always hidden spaces. This is one of the reasons why I write so much in Perl, and why, in Perl, I tell everyone on my team to avoid the shell when running external programs. There is so much power in the shell, with so many little things that can touch you, and I avoid them where possible. (And not where it is impossible).

+10
source

Source: https://habr.com/ru/post/1383987/


All Articles