bug-bash
[Top][All Lists]
Advanced

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

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


From: Chet Ramey
Subject: Re: $\n doesn't get expanded between double-quotes
Date: Fri, 03 Jul 2009 13:13:33 -0400
User-agent: Thunderbird 2.0.0.22 (Macintosh/20090605)

Richard Neill wrote:

> This is still a missing feature: how to embed newlines in double-quoted
> bash string assignment:
> 
> For example, if I want to write:
> 
> EMAIL_BODY="Dear $NAME,$'\n\n'Here are the log-files for
> $(date)$'\n\n'Regards,$'\n\n'$SENDER"
> 
> then this doesn't work. There are ways around it, such as:
>   - building up the string in pieces or
>   - EMAIL_BODY=$(echo -e "$EMAIL_BODY")
> 
> but it's really ugly to do.

A variant of the traditional idiom for this works fine:

TAB=$'\t'
NL=$'\n'

and using $TAB and $NL appropriately within the double-quoted string.

(The traditional idiom drops the $ and uses literal tabs and newlines
between single quotes.)

Chet


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]