Re: evaluation of env variables in DASH
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-) - - eblake@office (0) ~/libvirt $ (shopt -u xpg_echo; A='\n'; echo -$A-) -\n- Fix your shell script to use printf instead of echo if the thing you are printing might contain a backslash. -- Eric Blake ebl...@redhat.com+1-801-349-2682 Libvirt virtualization library http://libvirt.org -- To unsubscribe from this list: send the line unsubscribe dash in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: evaluation of env variables in DASH
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 majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: evaluation of env variables in DASH
... 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. -- To unsubscribe from this list: send the line unsubscribe dash in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html