mercredi 8 juillet 2015

Bash if statement not working properly

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.

#!/bin/bash
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"
    exit
fi
ARG=$1
if [ $ARG == "clean" ] ; then
    echo ">>> cleaning up object files..."
    rm -r src/*.o
    echo ">>> done. "
    echo ">>> Press enter to continue..."
    read
else
    #Builds program
fi

Aucun commentaire:

Enregistrer un commentaire