相关疑难解决方法(0)

如何在bash函数中使用heredoc?

是否可以在 bash 函数中插入一个heredoc

下面的简单示例会导致错误: ./heredoc_in_function.sh: 10: Syntax error: end of file unexpected (expecting "}")

#!/bin/sh

my_function () {
cat <<HEREDOC
heredoc contents
HEREDOC
}

my_function
Run Code Online (Sandbox Code Playgroud)

环境:

  • Ubuntu 11.04 (GNU/Linux 2.6.38-8-server x86_64)
  • GNU bash,版本 4.2.8(1)-release (x86_64-pc-linux-gnu)

ubuntu bash

13
推荐指数
1
解决办法
7653
查看次数

标签 统计

bash ×1

ubuntu ×1