You are not logged in.
Bash
For example
1) exo 2) garcon 3) gtk-xfce-engine 4) terminal 5) thunar 6) tumbler
7) xfce4-appfinder 8) xfce4-mixer 9) xfce4-panel 10) xfce4-session
11) xfce4-settings 12) xfce-utils 13) xfconf 14) xfdesktop 15) xfwm4
16) xfwm4-themes
Enter a selection (default = all):1 3 5 14
I tried the "command case" but only accepts one option
printf "%s\n" "List of options";
printf "%s\n" "1)option1 2)option2 3)option3";
printf "%s" "Choose the option:";
read -n 100 RESP
case "$RESP" in
1) PROTOCOL="test1";;
2) PROTOCOL="test2";;
3) PROTOCOL="test3";;
*) printf "Invalid option. Choose a valid number.\n"
exit 0;;
esac
List of options
1)option1 2)option2 3)option3
Choose the option:1 2
Invalid option. Choose a valid number.
Last edited by blueswat (2011-10-18 04:14:02)
Offline
Won't the for loop work?
This profile is scheduled for deletion.
Offline
With loop is possible to make a multi-selection?
Enter a selection (default = all):1 3 5 14
Or will have to select one at a time?
Enter a selection (default = all):1
Enter a selection (default = all):3
Enter a selection (default = all):5
Enter a selection (default = all):14
Offline
With the for loop you can give multiple inputs at once
Enter a selection (default = all):1 3 5 14
It will process each selection individually inside the script.
or you can also use the while
while [ -n "$*" ]
do
// do something with the argument $1
echo $1;
shift
done
This profile is scheduled for deletion.
Offline
This seems to do it ok
printf "%s\n" "List of options";
printf "%s\n" "1)option1 2)option2 3)option3";
printf "%s" "Choose the option:";
read -n 100 RESP
for i in $RESP; do
case "$i" in
1) PROTOCOL="test1";;
2) PROTOCOL="test2";;
3) PROTOCOL="test3";;
*) printf "Invalid option. Choose a valid number.\n"
exit 0;;
esac
done
exit 0
You're just jealous because the voices only talk to me.
Offline
Try this:
#!/bin/bash
declare -a options=(
exo garcon gtk-xfce-engine terminal thunar tumbler
xfce4-appfinder xfce4-mixer xfce4-panel xfce4-session
xfce4-settings xfce-utils xfconf xfdesktop xfwm4 xfwm4-themes
)
i=1
for o in "${options[@]}"; do
printf "%2d) %s\n" $(( i++ )) "$o"
done
echo -n $'\nChoose option(s): '
read -a choice
echo $'\nYou have chosen:'
for c in "${choice[@]}"; do
[[ "$c" -lt "1" ]] && printf "\nAbort: Unknown option %s\n" "$c" && exit 1
[[ "$c" -gt "${#options[@]}" ]] && printf "\nAbort: Unknown option %s\n" "$c" && exit 1
echo " ${options[$((c-1))]}"
done
When inputing the options, don't separate with commas. Do like this:
Choose option(s): 1 5 9
Last edited by rockin turtle (2011-10-18 01:29:50)
Offline
Thank you guys
I will try ...
then I post the result.
Offline