Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question [SOLVED] [Bash] New line character in variable


    How can I include a new line character in a variable in a bash shell script?
    echo $myvar # gives line1\nline2

    Doesn't work...and I have already tried many different combinations (\r\n, etc etc).

    Thanks in advance.


  2. #2
    $xxx = "abcd\

    don't sure it works , but try (=

  3. #3
    Quote Originally Posted by SergeS
    $xxx = "abcd\

    don't sure it works , but try (=
    Thanks for your suggestion but it doesn't work.

  4. $spacer_open
  5. #4

    Echo a newline character

    Since newline, tab and etc are escape characters.

    try this:

    echo -e "line1\nline2"

    -e to enable output escape characters

    This should works.

  6. #5


    echo -e works.

    Thank you

Posting Permissions

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