Hi, this is probably very easy but, how do I define a variable for more than one line.
For example:
var1='more
than
one
line'
when I call it, I want it to be exactly like this, don't want all the words on the same line.
Hi, this is probably very easy but, how do I define a variable for more than one line.
For example:
var1='more
than
one
line'
when I call it, I want it to be exactly like this, don't want all the words on the same line.
try
var1='more \n
than \n
one \n
line'
try
var1='more \n
than \n
one \n
line'
Thank you. I do this, than I do an "echo $var1" and this is what I get:
more \n than \n one \n line
I think the single quotes tells it to ignore the returns. When I use double quotes, I still get the same thing. ![]()
what OS. I tried it on MKS and HP-UX and it works fine..try \r or \r\n
I'm using the Bash shell.
Did you try echo "$var1" ?
Thank you very much, appreciate it a lot. Yes, this did the trick, now it works.
In fact, I don't even have to put "\n" when it's called like this.
well in fact even while assigning the variable if you put a " instead of a ', the \n would have worked
eg, var="multi\n
line\n
variable"
echo $var
multi
line
variable
No, it does not work for me. Tried it again just right now.
I get this:
echo $var
multi\n line\n variable
From the bash man page:
echo [-neE] [arg ...]
Output the args, separated by spaces, followed by a
newline. The return status is always 0. If -n is
specified, the trailing newline is suppressed. If the
-e option is given, interpretation of the following
backslash-escaped characters is enabled. The -E option
disables the interpretation of these escape characters,
even on systems where they are interpreted by default.
echo does not interpret -- to mean the end of options.
echo interprets the following escape sequences:
\a alert (bell)
\b backspace
\c suppress trailing newline
\e an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\nnn the character whose ASCII code is the octal value
nnn (one to three digits)
\xnnn
the character whose ASCII code is the hexadecimal
value nnn (one to three digits)
Therefore:
$ { AAA="a\nb\nc"; echo -e $AAA; }
produces:
a
b
c
And:
$ { AAA="a\nb\nc"; echo $AAA; }
produces:
a\nb\nc