如何在shellscripting中将命令结果存储在变量中? [英] How to store command results in a variable in on shellscripting?
本文介绍了如何在shellscripting中将命令结果存储在变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想找出主目录中目录和文件的数量,并想在shell脚本中存储一些变量.我正在使用以下命令集.
I want to find out number of directories and files in home directory and want to store count some variable in a shell script. I am using following set of commands.
command="ls -l | grep -c \"rahul.*patle\""
eval $command
我想将此计数存储到一些变量计数中.我该怎么做.
i want to store this count into some varibale count. How can i do this.
推荐答案
将命令输出存储到变量中的语法为var=$(command)
.
The syntax to store the command output into a variable is var=$(command)
.
因此您可以直接这样做:
So you can directly do:
result=$(ls -l | grep -c "rahul.*patle")
变量$result
将包含匹配数目.
这篇关于如何在shellscripting中将命令结果存储在变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文