将 awk 输出保存到变量 [英] Saving awk output to variable

查看:45
本文介绍了将 awk 输出保存到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮我解决这个问题?

Can anyone help me out with this problem?

我正在尝试将 awk 输出保存到变量中.

I'm trying to save the awk output into a variable.

variable = `ps -ef | grep "port 10 -" | grep -v "grep port 10 -"| awk '{printf "%s", $12}'`
printf "$variable"

$12 对应于在该进程上运行的参数.

$12 corresponds to a parameter running on that process.

谢谢!

推荐答案

#!/bin/bash

variable=`ps -ef | grep "port 10 -" | grep -v "grep port 10 -" | awk '{printf $12}'`
echo $variable

注意等号后面没有空格.

Notice that there's no space after the equal sign.

你也可以使用$(),它允许嵌套并且是可读的.

You can also use $() which allows nesting and is readable.

这篇关于将 awk 输出保存到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆