![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. Shell Script Page. |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| retrive lines from a file using AWK command | swamymns | Shell Programming and Scripting | 1 | 05-04-2008 06:47 PM |
| to retrive data that appear only once in a file. | anibu | Shell Programming and Scripting | 1 | 10-26-2007 07:54 AM |
| Retrive deleted file's info | asmita | UNIX for Advanced & Expert Users | 4 | 03-26-2007 10:36 PM |
| help to retrive data from log file | d_swapneel14 | Shell Programming and Scripting | 5 | 07-06-2006 01:57 AM |
| Reading file names from a file and executing the relative file from shell script | anushilrai | Shell Programming and Scripting | 4 | 03-10-2006 01:25 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
hi
i am new to shell scripting i have a properties file like hs=abc hs1=def hs2=ghi now i want to retrive each value and assign it to a variable like var1 = abc please help |
| Forum Sponsor | ||
|
|
|
|||
|
If the file's syntax is compatible with the shell's, you can simply use the source command, the lone dot:
Code:
. file.cf If that's not what you want, you could perhaps read in one line at a time, remove everything up through the first equals sign, and then assign the result to some variable. Code:
for var in var1 var2 var3
do
read line
eval $var=\""${line#*=}"\"
done <file.cf
The use of eval is a rather advanced technique; I would advise against this if you can come up with a simpler solution. |
|
|||
|
hi era
i am able to retrieve a value from a file, but i dont know how to assign the retrieved value to a variable. the code i have is #regressiontest.cfg hs=abc hs1=def hs2=ghi now i am retrieving the value from the above file RetrieveCfgvalue() { CFG_VALUE=`grep "$2=" $CONFIG_FILE_NAME | cut -d"=" -f2` CFG_VALUE=`echo $CFG_VALUE|sed -s "s/ *//g"` CFG_VALUE=`echo $CFG_VALUE|sed -s "s/\"//g"` if [ ! -z $CFG_VALUE ] then eval "$1=$CFG_VALUE" fi } CONFIG_FILE_NAME="regressiontest.cfg" RetrieveCfgvalue hs hs now i want to assign the retrieved value(hs) to a variable like var1 = abc please help quickly |
|
|||
|
Your function looks like it already does this. After RetrieveCfgvalue hs hs you should have the value of hs in the variable hs, isn't that correct? Then if you also want to assign it to var1, you can say var1=$hs (or simply RetrieveCfgvalue var1 hs directly, if that was what you were planning anyway).
|
|||
| Google UNIX.COM |