将命令的输出分配给变量

将命令的输出分配给变量

问题描述:

我是unix的新手,正在编写shell脚本.

I am new with unix and I am writing a shell script.

当我在命令提示符下运行此行时,它会打印出符合以下条件的进程总数:

When I run this line on the command prompt, it prints the total count of the number of processes which matches:

ps -ef | awk '/siebsvc –s siebsrvr/ && !/awk/ { a++ } END { print a }'

示例,在命令提示符下,上一行的输出为2.

example, the output of the above line is 2 in the command prompt.

我想编写一个shell脚本,其中将上述第(2)行的输出分配给一个变量,稍后将在if语句中将其用于比较.

I want to write a shell script in which the output of the above line (2) is assigned to a variable, which will be later be used for comparison in an if statement.

我正在寻找类似的东西

output= `ps -ef | awk '/siebsvc –s siebsrvr/ && !/awk/ { a++ } END { print a }'`
echo $output

但是当我运行它时,它说找不到输出,而我期望的是2.请帮助.

But when i run it, it says output could not be found whereas I am expecting 2. Please help.

您可以使用$符号,例如:

You can use a $ sign like:

OUTPUT=$(expression)