Re: Possible /bin/sh Bug?
On Tue, 05 Jun 2012 10:40:45 -0500
Tim Daneliuk <tundra@tundraware.com> wrote:
> Given this script:
> #!/bin/sh
>
> foo=""
> while read line
> do
> foo="$foo -e"
> done
> echo $foo
>
> Say I respond 3 times, I'd expect to see:
>
> -e -e -e
>
> Instead, I get:
>
> -e -e
The last line "echo $foo" is what is getting confused. At the end of
3 passes, $foo contains " -e -e -e" so when the last line is executed,
it looks like:
echo -e -e -e
The first -e is probably being interperted by "echo" as a flag
( echo -e ) and then only prints the last two -e.
Its easier to see if you execute the script with xtrace:
sh -x /path/to/script
I'd recommend that you write the last line with quotes:
echo "$foo"
and I think it'll produce the results you expect.
HTH,
Randy
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
討論串 (同標題文章)
完整討論串 (本文為第 5 之 5 篇):