简体   繁体   中英

bash script: how to run find command and variables

I'm new to it. x can not be recognized from above statement. 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

  2. you want the result of the command to be stored in x , so you need to execute the command (hence the $(...) )

这也应该起作用:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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