本文介绍了将awk命令存储在bash脚本的变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将 awk命令(命令,而不是结果)存储在变量中.我的目标是稍后在脚本中以不同的输入使用该变量.例如:

I'm trying to store an awk command (command, not the result) in a variable. My objective is to use that variable later in the script, with different inputs. For example:

cmd=$(awk '/something/ {if ...} {...} END {...}')
$cmd $input

我尝试将命令存储为$()(如示例中),也存储为backticks ...但是我无法实现.

I've tried to store the command with $() (like in the example), also with backticks ... But I'm not able to achieve it.

我感谢您的帮助或任何建议:)

I appreciate the help or any suggestion :)

推荐答案

忘记引号和括号.您只想存储awk脚本本身

Forget the backticks and parentheses. You just want to store the awk script itself

cmd='/something/ {if ...} {...} END {...}'
awk "$cmd" $input

这篇关于将awk命令存储在bash脚本的变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 20:18