case statement needs fixing

James Michael Fultz croooow at gmail.com
Fri Nov 20 08:39:39 UTC 2009


* Ray Parrish <crp at cmc.net> [2009-11-19 23:23 -0800]:
> I have the following code
> 
>      while read ThisLine; do
>            case "$ThisLine" in
>                 "<loc>"*)
>                          URLs="$URLs $ThisLine";;
>            esac
>      done < "$MapName"
> echo "URLs $URLs"
> 
> $MapName is assigned the name of a google site map file. I've tried 
> several variations to match the 
> <loc>http://www.somesite.com/index.html</loc> lines in the file so I can 
> concatenate them into one long string.
> 
> Still echo keeps dumping an empty string back at me, so I'm not sure 
> what I am doing wrong with this one.
> 
> Does anyone know why this is not working?

Loops in a pipeline run are run in a subshell.  There are a few
solutions to this.

<http://nion.modprobe.de/blog/archives/531-Altering-a-variable-outside-the-scope-of-a-loop-influenced-by-a-subshell.html>




More information about the ubuntu-users mailing list