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

后端 未结 1 871
长情又很酷
长情又很酷 2021-01-23 20:11

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

1条回答
  •  有刺的猬
    2021-01-23 20:59

    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'
    

    0 讨论(0)
提交回复
热议问题