FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 11-20-2009, 06:23 AM
Ray Parrish
 
Default case statement needs fixing

Hello,

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?

Thanks, Ray Parrish

--
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-20-2009, 07:24 AM
Ray Parrish
 
Default case statement needs fixing

Ray Parrish wrote:
> Hello,
>
> 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?
>
> Thanks, Ray Parrish
>
Hello again,

I figured it out, here is the corrected code -

while read ThisLine; do
case "$ThisLine" in
*<loc>*)
URLs="$URLs $ThisLine";;
esac
done < "$MapName"
echo "URLs $URLs"

I had to escape the <> symbols.

Later, Ray Parrish

--
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com



--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-20-2009, 07:39 AM
James Michael Fultz
 
Default case statement needs fixing

* Ray Parrish <crp@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>

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 11-20-2009, 09:40 PM
Cameron Hutchison
 
Default case statement needs fixing

James Michael Fultz <croooow@gmail.com> writes:

>* Ray Parrish <crp@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"
>>
>> 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.

You are correct about loops in a pipeline, but in this case there is
no pipeline, so the URLs assignment will be visible outside the loop.


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 07:43 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org