[kwlug-disc] wget and variable assignment
tim at tetro.net
Thu Jun 3 13:48:10 EDT 2010
On Thu, Jun 03, 2010 at 12:58:15PM -0400, Richard Weait wrote:
> GETTEE=`wget -q -O - http://www.openstreetmap.org/stats/data_stats.html`
> echo "GETTEE = $GETTEE"
> This returns a mess.
> The quick and dirty is to wget four times for four numbers, but I
> don't want to do that. How do I assign the wget to a variable and
> keep \n ?
The newlines are kept, you just need to be sure to quote it:
$ OUTPUT=`wget -q -O - http://google.com/`
$ echo $OUTPUT | wc -l
$ echo "$OUTPUT" | wc -l
The first is unquoted, and as a result gets split at whitespace
into separate arguments. The second gets passed a single
argument, since it's quoted. Below shows the argument count:
$ sh -c 'echo $#' - $OUTPUT
$ sh -c 'echo $#' - "$OUTPUT"
- Tim Utschig <tim at tetro.net>
More information about the kwlug-disc_kwlug.org