Find the answer to your Linux question:
Results 1 to 2 of 2
This is my script: $ cat Memo20 $ twoliner="This is line 1. > This is line 2." $ IFS="." $ echo "$twoliner" This is line 1. This is line 2. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2011
    Posts
    1

    having echo problems


    This is my script:

    $ 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

    As you can see I lose the . in the second echo. What do I have to do to get both echos to look the same?
    I am a newbie at Linux and need help

  2. #2
    Just Joined!
    Join Date
    Jun 2011
    Location
    Belgium
    Posts
    84
    IFS is the character to separates the text and is not displayed.
    More solutions are possible:
    1. Take a 'newline' as IFS (hexa value of newline is 0a).
      Code:
      $ twoliner="This is line 1.
      > This is line 2."
      $ IFS='#0a'
      $ echo $twoliner
      This is line 1.
      This is line 2.
    2. unset IFS and run 'echo -e' (see also '$ man echo')
      Code:
      $ twoliner="This is line 1.
      > This is line 2."
      $ unset IFS
      $ echo -e $twoliner
      This is line 1.
      This is line 2.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •