If the redirection operator is <<-, then all leading tab characters are stripped from input lines and the
line containing delimiter. This allows here-documents within shell scripts to be indented in a natural
fashion.
看起来像这样:
$ cat <<-_EOT_
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Morbi quis rutrum nisi, nec dignissim libero.
_EOT_
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Morbi quis rutrum nisi, nec dignissim libero.
可以使用sed从每行删除前导空格:
您可以选择(ab)use the fact that read will remove leading and trailing spaces:
^{pr2}$在您的示例中,您基本上希望删除所有空格:
不要缩进字符串,而是抑制导致需要缩进的初始换行符。在
“here document”功能允许将多行字符串定义为命令的输入:
^{pr2}$Bash手册section on here documents描述了一个允许在源代码中缩进的选项,并在读取文本时删除它:
看起来像这样:
问题是它只会去除制表符(U+0009)的缩进,而不是空格。如果您的编码风格禁止在源代码中使用制表符,那么这是一个严重的限制:-(
相关问题 更多 >
编程相关推荐