On 03-Apr-07 14:14:34, Chris G wrote:
On Tue, Apr 03, 2007 at 02:12:57PM +0100, David Reynolds wrote:
On 3 Apr 2007, at 1:43 pm, Chris G wrote:
I want to set a variable in a shell (bash) script with a newline as one of the characters.
First question, how do you do it? Second question, how do you prove it's there once you've done it?
I *think* there are several fairly obvious ways of doing it, e.g. things like:-
export fred="abcde ghijk"
However the problem is that using 'echo' to see what you have done is totally useless as echo does so many clever things under the cover that you don't get to see what's actually in the variable at all.
If you do the above and then say "echo $fred" you just get:-
abcde ghijk
Harrumph! *Surely* there's some way of saying "show me what's really in this variable/string" (a bit like 'od' but for variables).
A small amount of googling[1] finds this...
export test="bunch of \n text" echo $test bunch of \n text
echo -e $test bunch of text
Been there, done that, doesn't work for me! :-)
chrisg$ export fred="abcde \n fghij" chrisg$ echo "$fred" abcde \n fghij chrisg$
This is bash on FC6.
And it won't do what you want anyway -- the string contents of $fred will be "abcde \n fghij" (each character literally, apart from the "" of course).
What "echo -e" does is translate the "\n" into a newline when $fred ia read. There is no newline in $fred itself.
"-e enable interpretation of the backslash-escaped characters"
It looks as though MJR got the answer!
Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 03-Apr-07 Time: 15:28:47 ------------------------------ XFMail ------------------------------