Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 689
shaveax Avatar asked Nov 27 '25 21:11

shaveax


1 Answers

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
like image 146
jmunsch Avatar answered Nov 29 '25 14:11

jmunsch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!