Bash 让phantomjs运行所有';*。js';当前目录中的文件

Bash 让phantomjs运行所有';*。js';当前目录中的文件,bash,phantomjs,test-runner,Bash,Phantomjs,Test Runner,我想编写一个脚本,在目录中的一组测试脚本上调用phantomjs。 此脚本运行第一个测试,然后退出 #!/bin/bash find . -maxdepth 1 -name '*.js' -type f -exec phantomjs {} + 使用echo执行类似命令,如 find . -maxdepth 1 -name '*.js' -type f -exec echo {} + 按预期打印目录中的所有文件名 如何使phantomjs运行当前目录中的所有.js文件?这是bash问题还是

我想编写一个脚本,在目录中的一组测试脚本上调用
phantomjs
。 此脚本运行第一个测试,然后退出

#!/bin/bash

find . -maxdepth 1 -name '*.js' -type f -exec phantomjs {} +
使用
echo
执行类似命令,如

find . -maxdepth 1 -name '*.js' -type f -exec echo {} +
按预期打印目录中的所有文件名


如何使phantomjs运行当前目录中的所有
.js
文件?这是bash问题还是phantomjs问题?

AFAIK phantomjs一次只支持一个文件。您需要告诉
find
为每个找到的文件调用phantomjs:

#!/bin/sh
find . -maxdepth 1 -name '*.js' -type f -exec phantomjs {} ';'
您还可以使用:

#!/bin/sh
for file in *.js; do
  [ -f "$file" ] || continue
  phantomjs "$file"
done

一次为所有文件运行一个
phantomjs
进程是否重要?如果没有,则可以将
+
替换为
\
为每个文件运行一个
phantomjs