将grep计数分配给变量 [英] Assign grep count to variable
本文介绍了将grep计数分配给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何分配
grep -c "some text" /tmp/somePath
变成变量,以便我可以回显它.
into variable so I can echo it.
#!/bin/bash
some_var = grep -c "some text" /tmp/somePath
echo "var value is: ${some_var}"
我也尝试过:
some_var = 'grep -c \"some text\" /tmp/somePath'
但是我不断得到:command not found
.
推荐答案
要分配命令的输出,请使用var=$(cmd)
(如 shellcheck 自动告诉您是否将脚本粘贴到那里.
To assign the output of a command, use var=$(cmd)
(as shellcheck automatically tells you if you paste your script there).
#!/bin/bash
some_var=$(grep -c "some text" /tmp/somePath)
echo "var value is: ${some_var}"
这篇关于将grep计数分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文