how to parse the result of "set" command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to parse the result of "set" command
# 1  
Old 07-02-2008
how to parse the result of "set" command

Hello,

I would like to parse all the shell variables and get the name and the value for each variable. Set command get the list of variables but I don't know if there is a command such getopts to get each of them.

regards,

Teo
# 2  
Old 07-02-2008
is this what you are looking for?
Code:
for line in `set`; do  echo $line; done

# 3  
Old 07-02-2008
Oh, thanks, I've already use it but I have a problem. In addition to the shell variables it prints the rest of script begining with the method which calls the command set.
# 4  
Old 07-02-2008
As sample

for i in `set | grep urlWebservice`
do
field1_awk=`echo "$i" | awk -F= '{print $1}'| grep urlWebservice`
if [ $field1_awk != "" ] ; then
field2_awk=`echo "$i" | awk -F= '{print $2}'`
echo $field1_awk ":" $field2_awk
fi
done

it works but the last line displayed is for i in `set | grep urlWebservice`
# 5  
Old 07-02-2008
how does your set output look like, and what do you expect it to be in the end?
# 6  
Old 07-02-2008
My script contains this line at the begining

. ${DirName}/localConfiguration.conf

where localConfiguration.conf is a conf file

The content of the conf file is:

urlWebserviceCheckAddress=McoConfigGlobal.commonGLOBALUrlWebservice
urlWebserviceFindBillingAccount=McoConfigGlobal.commonGLOBALUrlWebservice
urlWebserviceGetBillingAccount=McoConfigGlobal.commonGLOBALUrlWebservice
urlWebserviceGetBillingAccountMovement=McoConfigGlobal.commonGLOBALUrlWebservice

The script must display these variables.
# 7  
Old 07-02-2008
don't see why you need to use set then
Code:
awk -F"=" '/urlWebservice/{print $1":"$2}' ${DirName}/localConfiguration.conf

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file(cou.data) which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Solaris

Netra X1 LOM: Unable to change any variable via the "set" command

I'm posting here as it didn't seem quite right in the hardware section (as it's LOM commands). My apologies if I have that wrong though :) I've finally gotten round to configuring the LOM on my Netra X1, but I can't get it to change the hostname via the "set" command: lom>show hostname... (2 Replies)
Discussion started by: Smiling Dragon
2 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Set command ending with a "." (dot)

Hi I have a "set" command which ends with a "." (dot), for example: set `grep "\<${pnum}\>" /tstmp/data.txt |sed 's/#//'` . Can somebody help me to understand the purpose of this "set" and "." combination? The problem is that this command does not produce the same result when run on AIX... (2 Replies)
Discussion started by: aoussenko
2 Replies

6. Shell Programming and Scripting

"Time" command and save result in a file.txt

Hi, I'am using "time" to check execution time of some script. Is there any possibility to save time command result into a file ? (2 Replies)
Discussion started by: Physix
2 Replies

7. Shell Programming and Scripting

How to distinguish between "command not found" and "command with no result"

system() call imeplemented in solaris is such a way that: Command not found - return code 1 Command executed successfully without Output - return code 1 how to distinguish between these two based on return code in a c - file? Can you help on this ? (5 Replies)
Discussion started by: iitmadhu
5 Replies

8. Programming

Differece between "env" and "set" command

Hi, Please clarify what is the difference between "env" and "set" command. I guess set will display the system variables and user defined variables. Thanks Sweta (1 Reply)
Discussion started by: sweta
1 Replies

9. UNIX for Advanced & Expert Users

Problems with "set pka0_host_id 6" command

I need to change the pka0_host_id 7 to 6 but the command "set pka0_host_id 6" returns "pka0_host_id protected from attempted operation". How can i do that? please i need some answers soon!!!!! thanx (1 Reply)
Discussion started by: Lestat
1 Replies

10. UNIX for Dummies Questions & Answers

Problems with "set pka0_host_id 6" command

I need to change the pka0_host_id 7 to 6 but the command "set pka0_host_id 6" returns "pka0_host_id protected from attempted operation". How can i do that? please i need some answers soon!!!!! thanx (1 Reply)
Discussion started by: Lestat
1 Replies
Login or Register to Ask a Question