[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: $\n doesn't get expanded between double-quotes
From: |
Chris F.A. Johnson |
Subject: |
Re: $\n doesn't get expanded between double-quotes |
Date: |
Fri, 3 Jul 2009 01:34:55 -0400 (EDT) |
User-agent: |
Alpine 2.00 (LMD 1167 2008-08-23) |
On Fri, 3 Jul 2009, fsc-log-rjn@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 syntax X="a"$'\n'"b c" will do it, but that is really really
> ugly.
X=$'a\nb c'
--
Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
- $\n doesn't get expanded between double-quotes ['PureMessage.Watchdog': checked], fsc-log-rjn, 2009/07/03
- Re: $\n doesn't get expanded between double-quotes,
Chris F.A. Johnson <=
- Re: $\n doesn't get expanded between double-quotes, Richard Neill, 2009/07/03
- Re: $\n doesn't get expanded between double-quotes, Andreas Schwab, 2009/07/03
- Re: $\n doesn't get expanded between double-quotes, Chris F.A. Johnson, 2009/07/03
- Re: $\n doesn't get expanded between double-quotes, Greg Wooledge, 2009/07/06
- Re: $\n doesn't get expanded between double-quotes, Dave B, 2009/07/03
- Re: $\n doesn't get expanded between double-quotes, Chet Ramey, 2009/07/03
- Re: $\n doesn't get expanded between double-quotes, Chet Ramey, 2009/07/03
- Re: $\n doesn't get expanded between double-quotes ['PureMessage.Watchdog': checked], Chet Ramey, 2009/07/03