I have a bash statement to test a command line argument. If the argument passed to the script is "clean", then the script removes all .o files. Otherwise, it builds a program. However, not matter what is passed (if anything), the script still thinks that the argument "clean" is being passed.

if test "`whoami`" != "root" ; then
    echo "You must be logged in as root to build (for loopback mounting)"
    echo "Enter 'su' or 'sudo bash' to switch to root"
if [ $ARG=="clean" ] ; then
    echo ">>> cleaning up object files..."
    rm -r src/*.o
    echo ">>> done. "
    echo ">>> Press enter to continue..."
    #Builds program

closed as off-topic by jasonwryan, Michael Homer, cuonglm, Archemar, Volker Siegel Jul 9 '15 at 7:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – jasonwryan, Michael Homer, cuonglm, Archemar, Volker Siegel
If this question can be reworded to fit the rules in the help center, please edit the question.


You need to separate the arguments to [ with spaces; also, the equality operator is a single =, and you should quote both sides:

if [ "$ARG" = "clean" ]; then
  • It's better to swap those values. Putting the literal on the lefthand side can help to avoid issues in some shells w/ expansions to test -option. – mikeserv Jul 9 '15 at 6:33

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