2

I want to write a script to call phantomjs on a bunch of test scripts in a directory. This script runs the first test and then exits.

#!/bin/bash

find . -maxdepth 1 -name '*.js' -type f -exec phantomjs {} +

Executing a similar command with echo, like

find . -maxdepth 1 -name '*.js' -type f -exec echo {} +

prints (as expected) all the filenames in the directory.

How can I make phantomjs run all .js files in the current directory? Is this a bash problem or a phantomjs problem?

meatspace
  • 859
  • 16
  • 25
  • 1
    Is it important to run a single `phantomjs` process for all the files at once? If not, then you can replace `+` with `\;` to run one `phantomjs` for each file. – janos May 24 '16 at 17:39

1 Answers1

3

AFAIK phantomjs will only support one file at the time. You need to tell find to call phantomjs for each found file:

#!/bin/sh
find . -maxdepth 1 -name '*.js' -type f -exec phantomjs {} ';'

You can also use:

#!/bin/sh
for file in *.js; do
  [ -f "$file" ] || continue
  phantomjs "$file"
done
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123