Skip to content

Instantly share code, notes, and snippets.

@KathanP19
Created December 30, 2021 06:05
Show Gist options
  • Save KathanP19/20e9ec4d6e51418f574245a3b3cf106f to your computer and use it in GitHub Desktop.
Save KathanP19/20e9ec4d6e51418f574245a3b3cf106f to your computer and use it in GitHub Desktop.
Template for bash Script with Arguments inside Flags.
#!/bin/bash
function first(){
echo "First Function";
}
function second(){
echo "Second Function";
}
function third(){
echo "Third Function";
}
while [ -n "$1" ]; do
case "$1" in
first) first;
OPTIND=2
while getopts "lo:" opt; do
case "${opt}" in
l) echo "Passsed In Option of First FUnction";
;;
o) echo "$OPTARG"
;;
esac
done
break ;;
second) second;
OPTIND=2
while getopts "l" opt; do
case "${opt}" in
l) echo "Passsed In Option of second FUnction";
;;
esac
done
break ;;
-help|--help|-h) echo "Usage: ";
echo -e " $0 first -l -o Argument_to_Param";
echo -e " $0 second -l";
exit 2;;
*)
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
echo "Non-option argument: '-${OPTARG}'";
fi
;;
esac
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment