[英]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 要回答你的问题,问题是
the space after x
causes the shell to try to execute the command x
which probably does not exist x
后面的空格导致shell尝试执行可能不存在的命令x
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.