3

I was wondering if is possible customize the select loop for bash.

I have this code:

select varName in list
do
case $varName in
    pattern1)
        command1;;
    pattern2)
        command2;;
    pattern1)
        command3;;
    *)
        echo "Error select option 1..3";;
esac            
done

Output is something like this:

 1) columbia    3) challenger  5) atlantis    7) pathfinder
 2) endeavour   4) discovery   6) enterprise
 #? 

I would like to order the options in landscape view and also change the prompt [#?] by something else

Thanks

1

1 Answer 1

2

select displays the PS3 prompt.

You could try something like:

echo $PS3
old_PS3=$PS3
export PS3="make a selection :D"
list='columbia challenger atlantis pathfinder endeavour discovery enterprise'
select varName in $list
do
case $varName in
    pattern1)
        command1;;
    pattern2)
        command2;;
    pattern1)
        command3;;
    *)
        echo "Error select option 1..3";;
esac            
done
# set PS3 back to original
export PS3=$old_PS3
Sign up to request clarification or add additional context in comments.

3 Comments

This works thanks, and what about landscape view ? , i appreciate it ;)
@shaveax Without getting into some quirky things using awk, and setting IFS and OFS, i would suggest looking into something like whiptail if you want to format the menus.
Also see: unix.stackexchange.com/questions/203309/… basically instead of trying to force select into a format you could use different tools to do the formatting something like column or printf or just plain old echo and a case statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.