2

I have this bash code:

usages() {
    echo "$0 --user= --pass= --serverName= --dbList="
    exit 1
}
while [[ "$1" != "" ]] && [[ ."$1" = .--* ]]; do
case $1 in
    "--user="* )
        DB_USER="${1#*=}"
        shift ;;
    "--pass="* )
        DB_PASS="${1#*=}"
        shift ;;
    "--dbList="* )
        DB_NAME="${1#*=}"
        shift ;;
    "--serverName="* )
        SERVER_NAME="${1#*=}"
        shift ;;
    --help )
        usages ;;
    * )
        usages ;;
esac
done

Let say the script name is test.sh when I run test.sh like this:

./test.sh --user=user1 --pass=pass1 --serverName=testing


The script still running. The problem is i need a arguments checker and it should check 4 parameter and arguments are presented. If not equal to 4 params it should run 'usages' function. Kindly help me. Thank you

J-Alex
  • 6,881
  • 10
  • 46
  • 64
dongK
  • 51
  • 4

0 Answers0