![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Simple loop in Bash | BrewDudeBob | Shell Programming and Scripting | 1 | 06-17-2008 02:08 PM |
| passing variable from bash to perl from bash script | arsidh | Shell Programming and Scripting | 10 | 06-04-2008 12:25 PM |
| Basic bash 'for loop' usage | Orange Stripes | Shell Programming and Scripting | 2 | 12-18-2007 08:58 PM |
| Bash while loop problem | Kweekwom | Shell Programming and Scripting | 5 | 07-23-2007 12:49 AM |
| loop does not execute in bash script? | fedora | Shell Programming and Scripting | 2 | 01-16-2007 12:38 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
bash and ksh: variable lost in loop in bash?
Hi,
I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh). The goal of my script if to read a "config file" (like "ini" file), and make various report. I really simplified my script and reproduce the problem. It seems that variable inside "while loop" are lost in bash, but not in ksh? Here's the script: #!/bin/bash function read_configfile { typeset configfile="$1" typeset Hostname="$2" grep '=' $configfile | sed "s/'//g" | while read ligne; do variable="$(echo "$ligne" | awk -F= '{print $1}')" value="$(echo "$ligne" awk -F= '{print $2}')" eval "$variable='$value'" done echo "Affectation=$Affectation" } read_configfile bogus.in $(hostname) And the bogus.in file: Affectation=Yes life is good When run, the output is Affectation= So... First of all I want to understand WHY the behavior is different. Is it because the way the "pipe" are processed? Second, I found a way to bypass this. I just put every "variable=value" in a file (echo equation >>file), and outside the loop I'm doing an eval, and it works. But I would prefer NOT to use temporary file, so if you have any suggestions... Thanks. Last edited by estienne; 08-25-2008 at 12:55 PM.. |
|
||||
|
Thanks a lot. I was afraid of that. I should have tested it more before posting. Grrrrrrrrr... I don't like this behavior of bash!
Thx. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|