简体   繁体   English

bash脚本:如何运行find命令和变量

[英]bash script: how to run find command and variables

I'm new to it. 我是新来的。 x can not be recognized from above statement. x无法从上述陈述中识别。 What is the problem? 问题是什么?

x = find . -name "*.java" | wc -l
echo $x

It should be 它应该是

x=$(find . -name "*.java" | wc -l)

(Note that there is no space around the = sign) (请注意, =号周围没有空格)


To answer your question, the problem is 要回答你的问题,问题是

  1. the space after x causes the shell to try to execute the command x which probably does not exist x后面的空格导致shell尝试执行可能不存在的命令x

  2. you want the result of the command to be stored in x , so you need to execute the command (hence the $(...) ) 您希望将命令的结果存储在x ,因此需要执行命令(因此$(...)

这也应该起作用:

x=`find . -name "*.java" | wc -l`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM