linux - 如何存储 ls 的值grep 测试 |变量中的 wc -l

标签 linux shell

$a=ls | grep test | wc -l

我想将 wc -l 计数存储在变量中,我不编写 shell 脚本

最佳答案

在像 bash 这样的 shell(zsh 等)上,你可以这样做

a=$(ls | grep test | wc -l)

您可以使用$a取回该值。 (例如echo $a)。

旧的语法是像这样使用反引号

a=`ls | grep test | wc -l`

但最好避免这种情况。它不嵌套,并且还有一些其他问题。

关于linux - 如何存储 ls 的值grep 测试 |变量中的 wc -l,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49291863/

相关文章:

linux - 内核升级后apt-get自动提示消失

linux - shell脚本不运行其中的其他脚本

php - 执行 Linux shell 脚本时出错

bash - 在 bash 脚本中向 git 提供密码

java - 使用 shell 脚本启动和终止 java 应用程序 (Debian)

c - 在linux中使用opengl进行像素操作的简单形式

linux - linux 上的 qt openGL 支持

shell - Emacs 口齿不清 : is it possible (using lisp) to run command in an eshell working in other buffer?

linux - 如何在 linux mint 下的 zsh 中设置 virtualenvwrapper?

linux - 如何杀死 Bash 中的子进程?