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
I think this is based on bash, so may be different in other shells.
Hope that helps,
David
[1] Go to http://www.google.co.uk and type in 'bash newline', hit the search button and marvel at the results.