simplify getopts loops in shell scripts

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-09-26 01:34:10 +01:00
parent 36b7f01a8a
commit 67f4919ffe
3 changed files with 15 additions and 35 deletions

View File

@ -38,26 +38,14 @@ main()
while getopts b:m:u:c:x: option while getopts b:m:u:c:x: option
do do
case "${1}" in case "${1}" in
-b) -b) mode="all" ;;
mode="all" -u) mode="oldconfig" ;;
shift ;; -m) mode="menuconfig" ;;
-u) -c) mode="distclean" ;;
mode="oldconfig" -x) mode="crossgcc-clean" ;;
shift ;; *) fail "Invalid option" ;;
-m)
mode="menuconfig"
shift ;;
-c)
mode="distclean"
shift ;;
-x)
mode="crossgcc-clean"
shift ;;
*)
fail "Invalid option" ;;
esac esac
project="${OPTARG}" shift; project="${OPTARG}"; shift
shift
done done
[ -z "${mode}" ] && fail "mode not given (-m, -u or -b)" [ -z "${mode}" ] && fail "mode not given (-m, -u or -b)"

View File

@ -15,16 +15,11 @@ main()
while getopts b:c: option while getopts b:c: option
do do
case "${1}" in case "${1}" in
-b) -b) : ;;
shift ;; -c) mode="distclean" ;;
-c) *) err "Invalid option" ;;
mode="distclean"
shift ;;
*)
err "Invalid option" ;;
esac esac
project="${OPTARG}" shift; project="${OPTARG}"; shift
shift
done done
[ -z "${project}" ] && err "project name not specified" [ -z "${project}" ] && err "project name not specified"

View File

@ -23,13 +23,10 @@ main()
while getopts r:b:m: option while getopts r:b:m: option
do do
case "${option}" in case "${option}" in
r) r) rom=${OPTARG} ;;
rom=${OPTARG} ;; b) board=${OPTARG} ;;
b) m) modifygbe=true
board=${OPTARG} ;; new_mac=${OPTARG} ;;
m)
modifygbe=true
new_mac=${OPTARG} ;;
esac esac
done done