1

Here is a simple script called command.sh:

#!/bin/bash

echo "I received: |$1|"

When I call it with a line feed, it doesn't output it:

$ ./command.sh foo\
> bar
I received: |foobar|

Why does the line feed get lost?

Stephan
  • 41,764
  • 65
  • 238
  • 329

1 Answers1

6

Call your script as:

./command.sh 'foo
> bar'

By placing \ before newline you're merely breaking current command line and not really passing newline character to your script.

If you want to do it in single line then use:

./command.sh $'foo\nbar'
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    Thanks for your quick answer. However, I have reworded my question. Can you please have a look at it here: http://stackoverflow.com/q/38642827/363573 ? – Stephan Jul 28 '16 at 17:19