I am trying to create an interactive bash shell script to make it easier to install and configure a postfix mail server,But have them still enter the commands and then the shell run them, but I keep getting this error and I don't know why.

These two lines are giving me the error "Too many arguments"

if test $VAR1 = sudo apt-get install postfix


until test $VAR1 = sudo apt-get install postfix



You need to quote the arguments to test to stop them 'breaking' on whitespace, i.e. if

$ var1="sudo apt-get install postfix"


$ if test $var1 = sudo apt-get install postfix; then echo "Match"; fi
bash: test: too many arguments


$ if test "$var1" = "sudo apt-get install postfix"; then echo "Match"; fi

The same applies if you use the [ ... ] test construct

if [ "$var1" = "sudo apt-get install postfix" ]; then echo "Match"; fi

As an aside, it's recommended not to use all-caps for your variable names - all-caps are generally reserved for system variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.