Shell script help

Steve Harvey sgh-Ja3L+HSX0kI at public.gmane.org
Tue Jul 3 22:33:41 UTC 2007


On Tue, Jul 03, 2007 at 02:56:41PM -0400, Neil Watson wrote:
> Could some kind sole explain why these outputs are different:
> 
> nhwatson at tor-lx-svn ~/test_repo/trunk $ ST=$(svn st); echo "$ST"
> ?      one
> ?      five
> !      bar
> !      four
> nhwatson at tor-lx-svn ~/test_repo/trunk $ ST=$(svn st); echo $ST
> ? one ? five ! bar ! four
> 
> Where do the new lines go in the second example?
> 
  Without the quotes, the value of ST is tokenized, throwing the
newlines and runs of spaces away, and is mapped into (8 in this case)
separate arguments to the echo command.  The echo command then uses a
single space as delimiter when formatting its output.  Protecting with
double quotes suppresses most processing except parameter substitution
in this case, resulting in a single argument to echo.  To further
illustrate, try replacing the echo with a invocation of this simple
script:

#!/bin/bash

echo "arg1 unquot "  $1
echo "arg1 quoted "  "$1"
echo "arg2 unquot "  $2
echo "arg2 quoted "  "$2"

-- 
Steve Harvey
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list