DASH Shell discussions
 help / color / mirror / Atom feed
* evaluation of env variables in DASH
@ 2011-10-19 21:24 Dima Sorkin
  2011-10-19 21:42 ` Eric Blake
  2011-10-19 21:58 ` Jilles Tjoelker
  0 siblings, 2 replies; 4+ messages in thread
From: Dima Sorkin @ 2011-10-19 21:24 UTC (permalink / raw)
  To: dash, herbert

Hi.
  The following DASH behaviour seems buggy to me

-----------------
$ export A='\n'
$ echo $A

$
-----------------

whereas using BASH would result in printing literally \n .

I.e. presumingly DASH does secondary interpolation of escaped
symols in values of environment variables. 

Please CC me with replies, I am not in the list.

Thanks, regards,
  Dima.

P.S.
  Wrom the other hand

$ export B=1
$ export A='$B'
$ echo $A
PRINTS $B
$

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: evaluation of env variables in DASH
  2011-10-19 21:24 evaluation of env variables in DASH Dima Sorkin
@ 2011-10-19 21:42 ` Eric Blake
  2011-10-19 21:58 ` Jilles Tjoelker
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Blake @ 2011-10-19 21:42 UTC (permalink / raw)
  To: Dima Sorkin; +Cc: dash, herbert

On 10/19/2011 03:24 PM, Dima Sorkin wrote:
> Hi.
>    The following DASH behaviour seems buggy to me

The only bug here is your expectations.

>
> -----------------
> $ export A='\n'
> $ echo $A
>

Passing a literal backslash to echo is non-portable.  POSIX even says 
so.  And bash can match dash behavior:

$ (shopt -s xpg_echo; A='\n'; echo -$A-)
-

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: evaluation of env variables in DASH
  2011-10-19 21:24 evaluation of env variables in DASH Dima Sorkin
  2011-10-19 21:42 ` Eric Blake
@ 2011-10-19 21:58 ` Jilles Tjoelker
  2011-10-19 22:13   ` Dima Sorkin
  1 sibling, 1 reply; 4+ messages in thread
From: Jilles Tjoelker @ 2011-10-19 21:58 UTC (permalink / raw)
  To: Dima Sorkin; +Cc: dash, herbert

On Wed, Oct 19, 2011 at 11:24:50PM +0200, Dima Sorkin wrote:
>   The following DASH behaviour seems buggy to me

> -----------------
> $ export A='\n'
> $ echo $A
> 
> $
> -----------------

> whereas using BASH would result in printing literally \n .

> I.e. presumingly DASH does secondary interpolation of escaped
> symols in values of environment variables. 

The echo builtin in dash differs from most other echo utilities on Linux
and *BSD in interpreting System V-like backslash escape sequences. This
is the "expansion" you are seeing and the same thing can be seen in
  echo '\n'
It is documented in dash's manual page.

This also happens in bash if you 'shopt -s xpg_echo'.

This behaviour is permitted by POSIX and required for the XSI option,
and is more commonly seen on Solaris or other System V derivatives.

The fix is to use printf(1) instead of echo(1) if there is a possibility
the string may start with '-' or contain '\'. In this case,
  printf '%s\n' "$A"

This has been asked/reported more frequently and the answer has been
that it will not be changed.

-- 
Jilles Tjoelker

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: evaluation of env variables in DASH
  2011-10-19 21:58 ` Jilles Tjoelker
@ 2011-10-19 22:13   ` Dima Sorkin
  0 siblings, 0 replies; 4+ messages in thread
From: Dima Sorkin @ 2011-10-19 22:13 UTC (permalink / raw)
  To: dash; +Cc: herbert


> ... The echo builtin in dash ...

What confused me is that I thought that /bin/echo is used, and wrong
argument is passed to it. I was not aware it is a builtin.

Thanks for replies, regards,
  Dima.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-10-19 22:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-19 21:24 evaluation of env variables in DASH Dima Sorkin
2011-10-19 21:42 ` Eric Blake
2011-10-19 21:58 ` Jilles Tjoelker
2011-10-19 22:13   ` Dima Sorkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox