相关疑难解决方法(0)

如何在Bash中为变量分配heredoc值?

我有这个多行字符串(包括引号):

abc'asdf"
$(dont-execute-this)
foo"bar"''
Run Code Online (Sandbox Code Playgroud)

如何在Bash中使用heredoc将其分配给变量?

我需要保留换行符.

我不想逃避字符串中的字符,这会很烦人......

bash heredoc

344
推荐指数
8
解决办法
16万
查看次数

如何在awk脚本中使用shell变量?

我找到了一些办法通过外壳变量的awk脚本,但我感到困惑'和".

首先,我尝试使用shell脚本:

$ v=123test
$ echo $v
123test
$ echo "$v"
123test
Run Code Online (Sandbox Code Playgroud)

然后尝试了awk:

$ awk 'BEGIN{print "'$v'"}'
$ 123test
$ awk 'BEGIN{print '"$v"'}'
$ 123
Run Code Online (Sandbox Code Playgroud)

为什么有区别?

最后我试过这个:

$ awk 'BEGIN{print " '$v' "}'
$  123test
$ awk 'BEGIN{print ' "$v" '}'
awk: cmd. line:1: BEGIN{print
awk: cmd. line:1:             ^ unexpected newline or end of string 
Run Code Online (Sandbox Code Playgroud)

我对此感到困惑.

bash shell awk

260
推荐指数
5
解决办法
46万
查看次数

标签 统计

bash ×2

awk ×1

heredoc ×1

shell ×1