LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   My script is not working right (https://www.linuxquestions.org/questions/linux-newbie-8/my-script-is-not-working-right-893397/)

kenny53067 07-23-2011 11:45 PM

My script is not working right
 
Can anyone tell me what is wrong?

$ cat Memo20
twoliner="This is line 1.
This is line 2."
$ IFS="."
echo "$twoliner"
This is line 1.
This is line 2.
echo $twoliner
This is line 1
This is line 2

With this script both echos should display the same, but they don't.

The first echo has . at the end of sentence.
The second echo does not have an .

Tinkster 07-24-2011 12:34 AM

Quote:

Can anyone tell me what is wrong?

$ cat Memo20
twoliner="This is line 1.
This is line 2."
$ IFS="."
echo "$twoliner"
This is line 1.
This is line 2.
echo $twoliner
This is line 1
This is line 2

With this script both echos should display the same, but they don't.

The first echo has . at the end of sentence.
The second echo does not have an .
Firstly I can't actually see a "script" as such, and the transcript
of shell activities you posted doesn't make too much sense to me.

Is this really what you did, with the results you posted?



Cheers,
Tink

kenny53067 07-24-2011 12:43 AM

Quote:

Originally Posted by Tinkster (Post 4423635)
Firstly I can't actually see a "script" as such, and the transcript
of shell activities you posted doesn't make too much sense to me.

Is this really what you did, with the results you posted?



Cheers,
Tink

This is what it looks like:
$ cat Memo20
twoliner="this is line 1.
This is line 2."
$ IFS="."
$ echo "$twoliners"
$ echo $twoliners

I added the IFS command.

Tinkster 07-24-2011 12:50 AM

Quote:

Originally Posted by kenny53067 (Post 4423636)
This is what it looks like:
$ cat Memo20
twoliner="this is line 1.
This is line 2."
$ IFS="."
$ echo "$twoliners"
$ echo $twoliners

I added the IFS command.

So where/how does the shell variable twoliners get
created/populated in your session? And looking at that
transcript the output (zippo) does look the same?



Cheers,
Tink

kenny53067 07-24-2011 01:02 AM

Quote:

Originally Posted by Tinkster (Post 4423638)
So where/how does the shell variable twoliners get
created/populated in your session? And looking at that
transcript the output (zippo) does look the same?



Cheers,
Tink

I don't know what you mean created/populated.
Without the IFS command I added the output of the echos is this:
echo1 is This is line 1.
This is line 2.

echo2 is This is line 1. This is line 2.

Does this help?

kenny53067 07-24-2011 01:08 AM

Quote:

Originally Posted by kenny53067 (Post 4423648)
I don't know what you mean created/populated.
Without the IFS command I added the output of the echos is this:
echo1 is This is line 1.
This is line 2.

echo2 is This is line 1. This is line 2.

Does this help?

It works if I add $ IFS=""

I figured it out, Thanks for the help!!


All times are GMT -5. The time now is 04:38 PM.