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.