$\n doesn't get expanded between double-quotes ['PureMessage.Watchdog': checked]

2009-07-02 Thread fsc-log-rjn
Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2 -Wall
uname output: Linux fsc-log 2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 
01:57:59 UTC 2009 i686 GNU/Linux
Machine Type: i486-pc-linux-gnu

Bash Version: 3.2
Patch Level: 48
Release Status: release

Description:
Bash allows escape characters to be embedded by using the $'\n'  
syntax. However, unlike all other $variables,
this doesn't work with embedded newlines. I think it should.

Repeat-By:
X="a$'\n'b c"
echo "$X"

expect to see:
a
b c

actually see:
a$'\n'b c


Fix:
$'\n'  should be expanded within double-quotes, like other variables 
are. 
Otherwise, please correct the man-page to make it clearer.

If this is a feature, not a bug, then is there a better way to include 
newlines in a variable-assignment?
The syntaxX="a"$'\n'"b c"will do it, but that is really really 
ugly.


Thanks,

Richard


This e-mail has been sent in confidence to the named
 addressee(s).  If you are not the intended recipient you
 must not disclose or distribute it in any form, and you are
 asked to contact the sender immediately

Unipart Group of Companies Ltd. Registered in England No. 1994997
Registered office: Unipart House, Cowley, Oxford, OX4 2PG




Re: $\n doesn't get expanded between double-quotes

2009-07-02 Thread Chris F.A. Johnson
On Fri, 3 Jul 2009, fsc-log-...@richardneill.org wrote:

> Configuration Information [Automatically generated, do not change]:
> Machine: i486
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' 
> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
> -DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2 
> -Wall
> uname output: Linux fsc-log 2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 
> 01:57:59 UTC 2009 i686 GNU/Linux
> Machine Type: i486-pc-linux-gnu
> 
> Bash Version: 3.2
> Patch Level: 48
> Release Status: release
> 
> Description:
>   Bash allows escape characters to be embedded by using the $'\n'  
> syntax. However, unlike all other $variables,
> this doesn't work with embedded newlines. I think it should.
> 
> Repeat-By:
>   X="a$'\n'b c"
>   echo "$X"
> 
>   expect to see:
>   a
>   b c
> 
>   actually see:
>   a$'\n'b c
> 
> 
> Fix:
>   $'\n'  should be expanded within double-quotes, like other variables 
> are. 
>   Otherwise, please correct the man-page to make it clearer.

   $'\n' is not a variable. As the man page says:

Words of the form $'string' are treated specially.

   Note "Words". Inside double quotes, $'\n' is not a word.


> 
>   If this is a feature, not a bug, then is there a better way to include 
> newlines in a variable-assignment?
>   The syntaxX="a"$'\n'"b c"will do it, but that is really really 
> ugly.

X=$'a\nb c'


-- 
   Chris F.A. Johnson, webmaster 
   ===
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)