Pregunta

I need to pass each filename that return find function to my script consider simple example:

find ./ -iname "*.java"  | xargs ./fnfs2lc.sh

and fnfs2lc.sh contains simple code:

#!/bin/bash
echo $1 
exit

Thus as a result I'm expecting to get list of files however it only shows the first file in the directory tree.

If I execute:

find ./ -iname "*.java"

result is:

./src/test/java/com/win/slots/picktables/SequnetialPickTableTest.java
./src/test/java/com/win/slots/picktables/WeightPickTableTest.java
./src/test/java/com/win/slots/picktables/AccuratePickTableTest.java
./src/test/java/com/win/slots/picktables/RangePickTableTest.java
./src/test/java/com/win/slots/picktables/KeyPickTableTest.java
./src/test/java/com/win/slots/api/WinningAmountTest.java
./src/test/java/com/win/slots/api/BIEventSenderTest.java
./src/test/java/com/win/slots/api/ParserTester.java
./src/test/java/com/win/slots/api/WindowTest.java

and if I run first command I get:

./src/test/java/com/win/slots/picktables/SequnetialPickTableTest.java

Do you know why it stops processing after first file ?

¿Fue útil?

Solución

Your script is using $1, so that is the first result in the list. If you want to print all results you could use:

#!/bin/bash
printf "%s\n" "$@"

Also, you do not need xargs, you could use

find . -iname "*.java" -exec ./fnfs2lc.sh {} +

If you use the less efficient

find . -iname "*.java" -exec ./fnfs2lc.sh {} \;

Then you could use

echo "$1"

But note the quotes around $1

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top