Hi All,
I have written a shell script which will list all directories in specified path and user has to select any directory out of it.
Code:
files=( $(find /apps/version -maxdepth 1 \( ! -regex '.*/\..*' \) -type d -printf 'P\n' | sort -rn ) )
PS3="Please enter the version number: "
select SEL in "${files[@]}"
do
if ! [ "$SEL" ]
then
echo "Choose one of the available files."
continue
fi
echo "$SEL version has been selected."
break
done
Executing this script will result below output:
Quote:
1) 10.03.051_01 10) 9.04.009_01 19) 7.06.012_01 28) 6.04.014_12
2) 10.03.050_01 11) 9.02.007_01 20) 7.06.009_01 29) 6.02.009_04
3) 10.03.049_01 12) 9.02.005_01 21) 7.04.011_01 30) 5.06.010_02
4) 10.02.010_01 13) 8.06.007_01 22) 7.04.006_01 31) 5.04.008_01
5) 10.02.009_01 14) 8.06.005_02 23) 7.02.011_01 32) 5.02.010_01
6) 10.02.008_03 15) 8.04.010_01 24) 7.02.008_01 33) 4.06.011_01
7) 9.06.011_01 16) 8.04.007_01 25) 6.06.017_02
8) 9.06.009_02 17) 8.02.011_05 26) 6.06.011_01
9) 9.04.011_01 18) 8.02.008_01 27) 6.04.016_01
Please enter the version number: 1
10.03.051_01 version has been selected.
|
Now, I wanted the output of PS3 variable to be formatted as
Quote:
1) 10.03.051_01 10) 9.04.009_01 19) 7.06.012_01 28) 6.04.014_12
2) 10.03.050_01 11) 9.02.007_01 20) 7.06.009_01 29) 6.02.009_04
3) 10.03.049_01 12) 9.02.005_01 21) 7.04.011_01 30) 5.06.010_02
4) 10.02.010_01 13) 8.06.007_01 22) 7.04.006_01 31) 5.04.008_01
5) 10.02.009_01 14) 8.06.005_02 23) 7.02.011_01 32) 5.02.010_01
6) 10.02.008_03 15) 8.04.010_01 24) 7.02.008_01 33) 4.06.011_01
7) 9.06.011_01 16) 8.04.007_01 25) 6.06.017_02
8) 9.06.009_02 17) 8.02.011_05 26) 6.06.011_01
9) 9.04.011_01 18) 8.02.008_01 27) 6.04.016_01
If indicated as available, appending a 'b' will select the beta version.
e.g. '1' selects stable version, '1b' selects beta version.
=============================================================================
Please enter your choice
|
Could you please help me to get the output in specified format.
Thanks in advanced.
Regards,
Yogesh