I'm writing a script to build a software from sources, and there's a --platforms
option. I would like to allow the user to select multiple items, but I don't know how to prevent them from making a mistake.
Example:
read -p "For what platforms do you wish to build [mac/win/linux32/linux64/all] ? "
if [[ -n "`echo $REPLY | grep 'win\|mac\|linux32\|linux64\|all`" ]] ; then
echo "ok"
else
echo "not ok"
fi
If the user answers linux32
, it should be OK (and it is)
If the user answers linux32,mac
, it should be OK (and it is)
If the user answers lulz
, it should NOT be OK (and it is not)
If the user answers linux32,lulz
, it should NOT be OK (and it is, that's my issue)
I was wondering if you knew a way to allow the user to input whatever they want separated by commas, but only if it's one of the options the script is offering, so in this case linux32 linux64 mac win all
.
Maybe with case
there is a way to allow multiple inputs, or maybe add an elif $REPLY contains anything else than what we want
. Another idea, could awk
be used? I can't figure out myself how to do that.
--platforms=
reads, and not OSX. That is how the build works, and I can't do anything about it.