Good day SO!
I'm working on a Django Project for learning purposes. Now I have a little bash script (working properly) to migrate my Django database and create a superuser with a onetoone profile.
Now I want to update my bash script so it recognizes some parameters. For example to automatically run the model migrations (makemigrations) or run the server after successfully migrating the database.
So I want to tell the bash to make migrations before migrating and run the server when finished (keys without values).
(venv)edwin@edwin:/project/installs/$ source install_database.sh -m -r
Now, I'm quite new to Linux and completely new to Straight Bash Space Separated bash scripts. I've read that using getopt[s] has no use in this case, since it can't handle empty argument strings.
So I attempted to create the Straight Bash Space Separated like:
#!/usr/bin/env bash
while [[ %# > 1 ]]
do
key=$1
case $key in
-m|--makemigrations)
MAKEMIGRATIONS=true
shift
;;
-r|--runserver)
RUNSERVER=true
shift
;;
*)
echo "invalid argument"
;;
esac
shift
done
echo "${RUNSERVER}"
echo "${MAKEMIGRATIONS}"
Whatever I attempt to initiate
(venv)edwin@edwin:/project/installs/$ source install_database.sh -m -r
(venv)edwin@edwin:/project/installs/$ source install_database.sh -m "test" -r "test"
(venv)edwin@edwin:/project/installs/$ source install_database.sh -m test -r test
I keep getting the result
false
false
Probably it's a beginners mistake, but I can't seem to figure it out... Can you give me an explanation of what I am doing wrong, and push me in the right direction to solve the problem?
Thanks in advance!