bash - 如何将换行符传递给脚本? [英] bash - How to pass a line feed to a script?
本文介绍了bash - 如何将换行符传递给脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个名为 command.sh 的简单脚本:
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|
为什么换行会丢失?
推荐答案
调用您的脚本为:
./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'
这篇关于bash - 如何将换行符传递给脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文