LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-18-2015, 03:23 AM   #1
yogesh_attarde
Member
 
Registered: Jan 2010
Posts: 82

Rep: Reputation: 1
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
 
Old 03-18-2015, 09:21 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,749

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by yogesh_attarde View Post
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.
 
Old 03-19-2015, 07:05 AM   #3
yogesh_attarde
Member
 
Registered: Jan 2010
Posts: 82

Original Poster
Rep: Reputation: 1
Thanks TB0ne, I am able to made changes to the PS3 variable and done.


Regards,
Yogesh
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell script output in .csv format mangal023 Linux - Newbie 3 02-24-2014 09:54 PM
shell script: saving output from command into a variable grcunning Linux - Newbie 7 01-26-2010 11:43 AM
passing awk output to $variable for shell script? NewnanNOC Programming 3 10-23-2008 02:08 PM
storing output of sed in a variable in shell script Fond_of_Opensource Linux - Newbie 1 11-09-2006 03:57 AM
Shell script help with function and output format altrob Programming 4 09-27-2006 02:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration