Re: evaluation of env variables in DASH

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux