LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Format output of PS3 variable in shell script (https://www.linuxquestions.org/questions/linux-software-2/format-output-of-ps3-variable-in-shell-script-4175537099/)

yogesh_attarde 03-18-2015 03:23 AM

Format output of PS3 variable in shell script
 
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

TB0ne 03-18-2015 09:21 AM

Quote:

Originally Posted by yogesh_attarde (Post 5333913)
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: Now, I wanted the output of PS3 variable to be formatted as Could you please help me to get the output in specified format.

Similar to another thread you posted:
http://www.linuxquestions.org/questi...il-4175519907/

..and just as confusing. If you wrote this shell script, you should already know how to make a simple modification to it. If you didn't, then show us what you've done/tried to make your changes so far, and we can try to help. The output you posted is the same, except you made a change to the prompt. If you want the PS3 variable changed, then edit the file and change it. It's clearly visible as the second line in what you posted. Change it to be whatever you want.

yogesh_attarde 03-19-2015 07:05 AM

Thanks TB0ne, I am able to made changes to the PS3 variable and done.


Regards,
Yogesh


All times are GMT -5. The time now is 03:46 PM.