- #1
gnome
- 1,041
- 1
Please take a look at these lines which demonstrate my problem in a korn shell terminal:
First I defined var with a newline embedded in it. I printed it and, as expected, got
abc
def.
I printed the same thing to file1.
Next, I edited it using the pattern operator ${var//\\n\} to remove the newline, printed it and again got what I expected. Now var is
abcdef
Then, I replaced var with the contents of file1: var=$(<file1)
Printed it, and again there's
abc
def
So far, so good.
Now, I try to edit it again with exactly the same command var=${var//\\n/}
But it has no effect. Var still prints as
abc
def
What's going on here? Is the newline represented differently in file1? How? How can I edit it out?
One other observation:
I noticed that in the FIRST instance, after defining var="abc\ndef", if I entered
print $var
I got
abc def
Only by entering
print "$var"
would I get
abc
def
But after reading it back in from the file, it prints as
abc
def
whether I enter
print "$var"
or
print $var
$ var="abc\ndef"
$ print "$var"
abc
def
$ print "$var" > file1
$ var=${var//\\n/}
$ print $var
abcdef
$ var=$(<file1)
$ print $var
abc
def
$ var=${var//\\n/}
$ print $var
abc
def
$
First I defined var with a newline embedded in it. I printed it and, as expected, got
abc
def.
I printed the same thing to file1.
Next, I edited it using the pattern operator ${var//\\n\} to remove the newline, printed it and again got what I expected. Now var is
abcdef
Then, I replaced var with the contents of file1: var=$(<file1)
Printed it, and again there's
abc
def
So far, so good.
Now, I try to edit it again with exactly the same command var=${var//\\n/}
But it has no effect. Var still prints as
abc
def
What's going on here? Is the newline represented differently in file1? How? How can I edit it out?
One other observation:
I noticed that in the FIRST instance, after defining var="abc\ndef", if I entered
print $var
I got
abc def
Only by entering
print "$var"
would I get
abc
def
But after reading it back in from the file, it prints as
abc
def
whether I enter
print "$var"
or
print $var