如何将包含空格的参数传递给包含gawk match()的脚本? [英] how to pass an argument containing whitespace to a script containing gawk match()?
本文介绍了如何将包含空格的参数传递给包含gawk match()的脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
>gawk 'match("", "foo bar", junk)'
是合法命令,我想在外壳程序脚本中将参数 foo bar
传递给它:
is a legitimate command, and I would like to pass the argument foo bar
to it inside a shell script:
foobar.sh
其中具有:
#!/bin/bash
gawk 'match("", "'$1'", junk)'
不起作用:
>./foobar.sh "foo bar"
gawk: match("", "foo
gawk: ^ unterminated string
该怎么做?
推荐答案
应使用 -v
选项传递:
gawk -v arg="foo bar" 'match("", arg, junk)'
这篇关于如何将包含空格的参数传递给包含gawk match()的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文