Skip to content
Advertisement

how to customize select loop in bash

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

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement