DASH Shell discussions
 help / color / mirror / Atom feed
From: Jilles Tjoelker <jilles@stack.nl>
To: Dima Sorkin <dima@minignu.minidns.net>
Cc: dash@vger.kernel.org, herbert@gondor.apana.org.au
Subject: Re: evaluation of env variables in DASH
Date: Wed, 19 Oct 2011 23:58:44 +0200	[thread overview]
Message-ID: <20111019215844.GA6049@stack.nl> (raw)
In-Reply-To: <87aa8woesd.fsf@minignu.minidns.net>

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

  parent reply	other threads:[~2011-10-19 22:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2011-10-19 22:13   ` Dima Sorkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111019215844.GA6049@stack.nl \
    --to=jilles@stack.nl \
    --cc=dash@vger.kernel.org \
    --cc=dima@minignu.minidns.net \
    --cc=herbert@gondor.apana.org.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox