tags:

views:

73

answers:

6

I have a for loop I'd like to run in bash like:

for i in user_* do; cat $i | ./fetch_contact.php ; done;

Always gives an error like

-bash: syntax error near unexpected token `done'

I assume it has something to do with the pipe, but nothing I try to add in (parenthesis, etc) wrap the pipe sufficiently. How do you use a pipe in a command like this?

A: 

foreach i in user_*; do cat $i | ./fetch_contact.php ; done;

Semicolon should go before do, not after.

bta
+1  A: 

Turns out getting the semicolons and everything else right makes this whole pipe thing moot.

for i in user_*; do cat $i | ./fetch_contact.php; done;
Allan
+2  A: 

In Bash, do is a command. Also, it is for not foreach. Here's the fix:

for i in user_*; do cat $i | ./fetch_contact.php; done;
Brett Daniel
+1  A: 

Why loop?

cat user_* | ./fetch_contact.php
Idelic
Because this concatenates all the files before feeding them to the script, which may not be what the OP wants.
Ignacio Vazquez-Abrams
If the OP runs it like what he posted in his questions, than catting everything to php script is equivalent to using for loop.
ghostdog74
A: 

No need for cat:

for i in user_* ; do ./fetch_contact.php < "$i" ; done
Ignacio Vazquez-Abrams
A: 

here's one with some checking

for file in user_*
do
  if [ -f "$file" ];then
    ./fetch_contact.php < "$file"
  fi
done
ghostdog74