Pages

vendredi 14 septembre 2007

FAIRE UN MENU DE CHOIX EN SHELL

The select statement is a bash specific extension and is very good for interactive use. The user can select a choice from a list of different values:

select var in ... ; do
break
done
.... now $var can be used ....

Here is an example:

#!/bin/sh
echo "What is your favourite OS?"
select var in "Linux" "Gnu Hurd" "Free BSD" "Other"; do
break
done
echo "You have selected $var"

Here is what the script does:

What is your favourite OS?
1) Linux
2) Gnu Hurd
3) Free BSD
4) Other
#? 1
You have selected Linux

Aucun commentaire:

Archives du blog