J'ai un script bash comme ci-dessous dans un fichier nepleaks_upd.sh, que je veux exécuter ./nepleaks_upd.sh bootstrap --branch off. Impossible de le faire prendre --branch, mais avec quoi ça marche ./nepleaks_upd.sh bootstrap -b off.
usage() { echo "Usage: $0 [prepare | up | down] [-b <on/off>]" 1>&2; exit 1; }
case "$1" in
bootstrap)
while getopts ":b:" o; do
case "${o}" in
b)
b=${OPTARG}
if [ ${b} == "off" ]; then
echo "git clone https://github.com/iPrayag/dotfiles.git"
## logic
fi
;;
*)
echo ${o}
usage
;;
esac
done
shift $((OPTIND-1))
echo "option1 = ${o}"
echo "option2 = ${b}"
if [ -z "${b}" ]; then
usage
fi
;;
up)
echo "up"
##logic
;;
down)
echo "down"
##logic
;;
*)
echo "Usage: $0 {up | down} dev"
exit 1
;;
esac
Sans d'abord case .. in .... esac, cela fonctionne bien. Avec case ... in ... esac, il donne une option vide pour -b,
$ ./nepleaks_upd.sh bootstrap -b off
option1 = ?
option2 =
Usage: ./nepleaks_upd.sh [bootstrap | up | down] [-b <on/off>]
case .. in .... esac, ça marche bien»? Voulez-vous dire que les lignes 5-25 analysent ./nepleaks_upd.sh -b offcorrectement? Peut-être que vous en avez besoin shift, alors getoptsne vous étouffez pas avec le « bootstrap».
$1?