A variable looses its value in a a while loop on Fedora 14
Please help with a problem in a script file.
This is my script file. The value of S is lost after the first loop completed. #!/bin/bash REPORTFILE=/tmp/testreport.txt V=`adder -V | awk '{print substr($1, 0, length($1)-1);}'` mkdir -p reports/$V > /dev/null 2>&1 cat testall.conf | while read S do echo "Doing $S ..." rm -f $REPORTFILE > /dev/null 2>&1 ./test.sh $S > /dev/null 2>&1 if [ -s $REPORTFILE ] then mv $REPORTFILE reports/$V/$S.txt > /dev/null 2>&1 else echo "$REPORTFILE for $S not found" > reports/$V/$S.txt fi done echo Only the first line in testall.conf is read the the script exit. After running the script the variable $S is empty. |
Hi,
Quote:
Code:
#/bin/bash Quote:
Evo2. |
Variable looses it's value
Thank you, I did that and all the lines in the file testall.conf were displayed. When the test.sh script (within the testall script) $S is empty after the first file in testall.conf is processed and the script goes out of the loop
|
Quote:
|
Hi,
Quote:
Quote:
Evo2. |
Hi,
Quote:
Evo2. |
I would add that the following two statements are not the same:
Quote:
Code:
while ... |
Quote:
|
FWIW, i did have bad ram that caused something like the actual description here. "Variable losing a value after x."
|
One additional possible reason:
test.sh (or something inside it) accepts input from stdin, therefore it will/may slurp out all the content and the next read will only get EOF. You can avoid happening this by: Code:
cat file | while read S |
Fedora 14 is end of life, out of support since 2011!
Any reason why you havent installed a newer, supported version? |
All times are GMT -5. The time now is 03:59 AM. |