Stephan Stephan - 1 year ago 84
Bash Question

bash - How to pass a line feed to a script?

Here is a simple script called


echo "I received: |$1|"

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

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

Why does the line feed get lost?

Answer Source

Call your script as:

./ '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:

./ $'foo\nbar'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download