io di solito faccio cosi' (ho fatto copia incolla da uno scriptino che ho fatto tempo fa):
In pratica in un for scorro i parametri, nella forma -nomeParametro valoreParametro
in $(eval echo \$$(($count + 1))) c'e' sempre valoreParametro.
Di sicuro si puo' fare piu' elegantemente o efficientemente, ma questo funziona.
Codice PHP:
#Check options
count=1
for param in $@; do
case $param in
-dir)
BASE_DIR=$(eval echo \$$(($count + 1)))
BASE_DIR_SET=1;;
-pre)
PRE_INSTALL="$(eval echo \$$(($count + 1)))"
if [[ ! -f $PRE_INSTALL ]]; then
echo "Pre-install script doesn't exist, terminating."
exit 1
fi;;
-post)
POST_INSTALL="$(eval echo \$$(($count + 1)))"
if [[ ! -f $POST_INSTALL ]]; then
echo "Post-install script doesn't exist, terminating."
exit 1
fi;;
-f)
INSTALLER_FILENAME=$(eval echo \$$(($count + 1)));;
-help)
clear
grep -v "bin/bash" $0 |grep "#&"|cut -d '&' -f 2 | more
exit 0;;
-about)
grep -v "bin/bash" $0 |grep "#%"|cut -d '%' -f 2
exit 0;;
-*)
echo -e "Invalid option.\n"
grep -v "bin/bash" $0 |grep "#~"|cut -d '~' -f 2
exit 0;;
esac
count=$(($count + 1))
done