I'm learning Bash, and I've written a basic function:
wsgc () {
# Wipe the global variable value for `getopts`.
OPTIND=1;
echo "git add -A";
while getopts m:p option;
do
case "${option}"
in
m)
COMMIT_MESSAGE=$OPTARG
if [ "$COMMIT_MESSAGE" ]; then
echo "git commit -m \"$COMMIT_MESSAGE.\""
else
echo "A commit message is required."
exit
fi
;;
p)
echo "git push"
exit
;;
\?)
echo "Invalid parameter."
exit
;;
esac
done
}
However, I'm struggling with a couple of things:
the
ifinm)isn't working, in that if I omit the argument, Bash intercedes and kicks me out of the session;git add -A -bash: option requires an argument -- m Invalid parameter. logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed.[Process completed]
After running:
wsgc -m "Yo!" -p, I get kicked out of the session.git add -A git commit -m "Yo." git push logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed.[Process completed]
Any advice would be much appreciated.