[BASH] non-empty variable before loop end, is empty after exiting loop
Hi fellows:
I'm having a quite disturbing trouble with this simple script: Code:
#!/bin/bash Code:
101993 I'm using a Ubuntu 10.04 64bits box. Thx! |
It's a simple and common mistake. You used a pipe to feed the output of find into the while loop, which means it runs in a subshell. The subshell can't affect the parent process, so the settings are lost when it exits.
You need to reposition the input as a redirect instead. Something like this (untested): Code:
while read vid; do http://mywiki.wooledge.org/BashPitfalls |
Thanks a lot, now i see. I was expecting something like that, so i tried to "export" the variable in some way.
I searched for the answer at LQ, but was sort of difficult to figure out how to search such a problem (loop + variable + empty ¿?). Sorry for reiteration. |
All times are GMT -5. The time now is 10:38 AM. |