Created
July 15, 2016 14:33
-
-
Save kairos34/9bd67afb1f2ba64641c5df8a07f1d82c to your computer and use it in GitHub Desktop.
Parsing args via bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parse_config_values() { | |
serial_obtained=false | |
shift | |
while [[ $# -gt 1 ]]; do | |
case "$1" in | |
--serial) | |
config_serial=$2 | |
echo $config_serial | |
serial_obtained=true | |
shift | |
;; | |
--rfid) | |
if [[ " ${RFIDS[@]} " =~ " ${2} " ]]; then | |
config_rfid_id="$2" | |
echo $config_rfid_id | |
else | |
echo "You provided wrong rfid option" | |
exit 1 | |
fi | |
shift | |
;; | |
--fp) | |
if [ "$2" == "false" ]; then | |
config_fp=false | |
echo $config_fp | |
fi | |
shift | |
;; | |
--3g) | |
if [ "$2" == "false" ]; then | |
config_3g=false | |
echo $config_3g | |
fi | |
shift | |
;; | |
*) | |
echo "Invalid argument: $1 for config values!" | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
if [ $serial_obtained = false ]; then | |
echo "You did not provide serial number, can not countinue!" | |
exit 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment