[SOLVED] Bash select string length for prompts?
by GPGAgent from LinuxQuestions.org on (#51W9X)
Okay, I'm using the select syntax in my bash script to select an option.
The string length of the options seems to cause wrapping if longer than 11 characters, is there any way around this?
Here are two examples showing the effect
Option length 11 ch
Code:#!/bin/bash
PS3='Please enter your choice: '
options=(
#123456789012#
"phone16kbps"
"sw 24kbps"
"mw-us40kbps"
"voice56kbps"
"Quit")
select opt in "${options[@]}"
do
case $opt in
"$1")
echo "you chose choice $REPLY which is $opt"
;;
"$2")
echo "you chose choice $REPLY which is $opt"
;;
"$3")
echo "you chose choice $REPLY which is $opt"
;;
"$4")
echo "you chose choice $REPLY which is $opt"
;;
"Quit")
break
;;
*) echo "invalid option $REPLY";;
esac
doneResults in this:
Code:charlie@charlie-machine:~$ options.sh
1) phone16kbps
2) sw 24kbps
3) mw-us40kbps
4) voice56kbps
5) Quit
Please enter your choice: 5
charlie@charlie-machine:~$And adding one character, option length 12 ch:
Code:#!/bin/bash
PS3='Please enter your choice: '
options=(
#123456789012#
"phone 16kbps"
"sw 24kbps"
"mw-us 40kbps"
"voice 56kbps"
"Quit")
select opt in "${options[@]}"
...Results in this:
Code:charlie@charlie-machine:~$ options.sh
1) phone 16kbps 3) mw-us 40kbps 5) Quit
2) sw 24kbps 4) voice 56kbps
Please enter your choice: 5
charlie@charlie-machine:~$I think that illustrates the effect.
Maybe there's another way to select an option without using the select syntax, and I'm looking for a bash solution, I'd prefer not to use xenity or dialog.


The string length of the options seems to cause wrapping if longer than 11 characters, is there any way around this?
Here are two examples showing the effect
Option length 11 ch
Code:#!/bin/bash
PS3='Please enter your choice: '
options=(
#123456789012#
"phone16kbps"
"sw 24kbps"
"mw-us40kbps"
"voice56kbps"
"Quit")
select opt in "${options[@]}"
do
case $opt in
"$1")
echo "you chose choice $REPLY which is $opt"
;;
"$2")
echo "you chose choice $REPLY which is $opt"
;;
"$3")
echo "you chose choice $REPLY which is $opt"
;;
"$4")
echo "you chose choice $REPLY which is $opt"
;;
"Quit")
break
;;
*) echo "invalid option $REPLY";;
esac
doneResults in this:
Code:charlie@charlie-machine:~$ options.sh
1) phone16kbps
2) sw 24kbps
3) mw-us40kbps
4) voice56kbps
5) Quit
Please enter your choice: 5
charlie@charlie-machine:~$And adding one character, option length 12 ch:
Code:#!/bin/bash
PS3='Please enter your choice: '
options=(
#123456789012#
"phone 16kbps"
"sw 24kbps"
"mw-us 40kbps"
"voice 56kbps"
"Quit")
select opt in "${options[@]}"
...Results in this:
Code:charlie@charlie-machine:~$ options.sh
1) phone 16kbps 3) mw-us 40kbps 5) Quit
2) sw 24kbps 4) voice 56kbps
Please enter your choice: 5
charlie@charlie-machine:~$I think that illustrates the effect.
Maybe there's another way to select an option without using the select syntax, and I'm looking for a bash solution, I'd prefer not to use xenity or dialog.