[英]how to store a value of ls | grep test | wc -l in variablels
$a=ls | grep test | wc -l
我想将wc -l count存储在一个变量中,我不使用shell脚本
On bash like shells (zsh etc.), you can do 在bash之类的shell(zsh等)上,您可以执行
a=$(ls | grep test | wc -l)
You can get the value back using $a
. 您可以使用$a
取回值。 (eg echo $a
). (例如echo $a
)。
The older syntax was to use backticks like so 较旧的语法是像这样使用反引号
a=`ls | grep test | wc -l`
but this is best avoided. 但这是最好的避免方法。 It doesn't nest and has a few other problems as well. 它不嵌套,并且还有其他一些问题。
Just use backtick (`) 只需使用反引号(`)
$ a=`ls | grep test | wc -l`
$ echo $a
1
You can use something like the below example. 您可以使用类似以下示例的内容。
a=$(ls | grep test | wc -l)
echo $a
Lemme know if it works. Lemme知道它是否有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.