简体   繁体   English

在awk中使用getline时,传递命令行参数并在命令中使用它

[英]Pass a command line argument and use it in a command when using getline in awk

I have a bash script which takes in 3 command line arguments. 我有一个bash脚本,它接受3个命令行参数。 In the same bash script, I've also got an awk command where I am using this type of getline command | getline var 在同一bash脚本中,我也有一个awk命令,我正在使用这种类型的getline command | getline var command | getline var . command | getline var

I want to be able to pass in the second command line argument into the command. 我希望能够将第二个命令行参数传递给命令。 How can I go about this? 我该怎么办?

It sounds as though you want a construct somewhat like: 听起来好像您想要一个类似的构造:

awk -v COMMAND="${2}" '{ system(COMMAND) | getline var }' -

As no detail is provided in the question, and since context for the "command | getline var" command is not provided in the question, this is a silly awk script that does nothing useful. 由于问题中没有提供任何详细信息,并且由于问题中未提供“ command | getline var”命令的上下文,因此这是一个愚蠢的awk脚本,无济于事。 It is meant only to show how to pass variables into an awk script from within a BASH context. 它仅旨在显示如何从BASH上下文中将变量传递到awk脚本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM