Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Jun 2012 11:35:22 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Tim Daneliuk <tundra@tundraware.com>
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: Possible /bin/sh Bug?
Message-ID:  <20120605163522.GD16874@dan.emsphone.com>
In-Reply-To: <4FCE287D.3090501@tundraware.com>
References:  <4FCE287D.3090501@tundraware.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Jun 05), Tim Daneliuk said:
> 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
> 
> Linux appears to do the right thing here, so this seems like it
> is a bug ... or am I missing something?

echo takes a -e flag, so it eats the first one.  Bash does the same thing,
so any Linux that uses bash as /bin/sh will also.  You must be testing on a
Linux that uses something else as /bin/sh.  Better to use the printf command
if you are worried about compatibility.

     echo [-e | -n] [string ...]
             Print a space-separated list of the arguments to the standard
             output and append a newline character.

             -n      Suppress the output of the trailing newline.

             -e      Process C-style backslash escape sequences.  The echo
                     command understands the following character escapes:


-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120605163522.GD16874>