I want to create a bash script which will have lot of options while executing.
# script.sh --dry-run --user <parameter1> --pass <parameter2>
I heard about getopt option but looks like we can only write either --user or --password or --dry-run and not all of them. Basically I want to take --user parameter1 as input1 and --pass parameter2 as input2 and a special case where if --dry-run option is there, then execute only dry-run code instead of production.
#!/bin/bash
user=$1
pass=$2
help() {
cat<<EOF
Usage : $0 --dry-run --user <user_id> --pass <password>
you can specify --dry-run or --production
EOF
}
[ ${3} ] || help
function dry_run() {
// --dry-run code
}
function production() {
// --production code
}
I want to validate --dry-run and if the option is --dry-run, then execute function dry_run() else execute production() function.
But how to write options and validations ?