PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > bash: process substitution not working in script
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

bash: process substitution not working in script

Réponse
 
LinkBack Outils de la discussion
Vieux 29/04/2008, 19h03   #1
lihao0129@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut bash: process substitution not working in script

I have a bash script which accept two input, one from a file, another
from the output of a shell pipeline. thought I can use process
substitution here, like:

awk -F'.' '
FNR == NR {
# do_sth();
next;
} {
# do_other_thing();
}
' file1.txt <( find -type f -exec file {}
+ | \
awk -F: '$2~/image/{split($1,b,"/")rint
b[2]}' | \
sort -nk1 | uniq -
c' \
)

This works pretty well under command-line, but when I wrapped up
exactly the above lines into a shell script(since I need to test over
different directories), it did not work. the error shows:



../script.sh: line 30: syntax error near unexpected token `('
../script.sh: line 30: `' file1.txt <( find -type f -exec file {}
+ | \'

I checked the man page about the process substitution which mentioned
the named pipe. since I am not familiar with this part, could someone
me with this problem? many thanks,

Best,
lihao
  Réponse avec citation
Vieux 29/04/2008, 19h38   #2
Dave B
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash: process substitution not working in script

On Tuesday 29 April 2008 20:03, lihao0129@gmail.com wrote:

> I have a bash script which accept two input, one from a file, another
> from the output of a shell pipeline. thought I can use process
> substitution here, like:
>
> awk -F'.' '
> FNR == NR {
> # do_sth();
> next;
> } {
> # do_other_thing();
> }
> ' file1.txt <( find -type f -exec file {}
> + | \
> awk -F: '$2~/image/{split($1,b,"/")rint
> b[2]}' | \
> sort -nk1 | uniq -
> c' \
> )


It looks like the above script has an unmatched single quote (the one after
c, penultimate line).
And, why is the script formatted that way? Is all that caused just by line
wraps?

--
D.
  Réponse avec citation
Vieux 29/04/2008, 19h42   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash: process substitution not working in script

On 4/29/2008 1:03 PM, lihao0129@gmail.com wrote:
> I have a bash script which accept two input, one from a file, another
> from the output of a shell pipeline. thought I can use process
> substitution here, like:
>
> awk -F'.' '
> FNR == NR {
> # do_sth();
> next;
> } {
> # do_other_thing();
> }
> ' file1.txt <( find -type f -exec file {}
> + | \
> awk -F: '$2~/image/{split($1,b,"/")rint
> b[2]}' | \
> sort -nk1 | uniq -
> c' \
> )
>
> This works pretty well under command-line, but when I wrapped up
> exactly the above lines into a shell script(since I need to test over
> different directories), it did not work. the error shows:
>
>
>
> ./script.sh: line 30: syntax error near unexpected token `('
> ./script.sh: line 30: `' file1.txt <( find -type f -exec file {}
> + | \'
>
> I checked the man page about the process substitution which mentioned
> the named pipe. since I am not familiar with this part, could someone
> me with this problem? many thanks,
>


Since there's line-wrapping, etc. in your posting, it's hard to say what's
causing the problem, but in any case all you really need here is a pipeline:

find ... | awk ... | sort ... | uniq ... |
awk -F'.' '
FNR == NR {
# do_sth()
next
} {
# do_other_thing()
}
' file1.txt -

Note the "-" sign at the end to tell awk to read stdin after reading file1.txt.

Regards,

Ed.

  Réponse avec citation
Vieux 29/04/2008, 19h42   #4
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash: process substitution not working in script

On 2008-04-29, lihao0129@gmail.com <lihao0129@gmail.com> wrote:
>
>
> ./script.sh: line 30: syntax error near unexpected token `('
> ./script.sh: line 30: `' file1.txt <( find -type f -exec file {}
> + | \'
>
> I checked the man page about the process substitution which mentioned
> the named pipe. since I am not familiar with this part, could someone
> me with this problem? many thanks,
>

Does your script begin with #!/bin/bash?
  Réponse avec citation
Vieux 29/04/2008, 20h39   #5
lihao0129@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash: process substitution not working in script

On Apr 29, 2:42 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 4/29/2008 1:03 PM, lihao0...@gmail.com wrote:
>
>
>
> > I have a bash script which accept two input, one from a file, another
> > from the output of a shell pipeline. thought I can use process
> > substitution here, like:

>
> > awk -F'.' '
> > FNR == NR {
> > # do_sth();
> > next;
> > } {
> > # do_other_thing();
> > }
> > ' file1.txt <( find -type f -exec file {}
> > + | \
> > awk -F: '$2~/image/{split($1,b,"/")rint
> > b[2]}' | \
> > sort -nk1 | uniq -
> > c' \
> > )

>
> > This works pretty well under command-line, but when I wrapped up
> > exactly the above lines into a shell script(since I need to test over
> > different directories), it did not work. the error shows:

>
> > ./script.sh: line 30: syntax error near unexpected token `('
> > ./script.sh: line 30: `' file1.txt <( find -type f -exec file {}
> > + | \'

>
> > I checked the man page about the process substitution which mentioned
> > the named pipe. since I am not familiar with this part, could someone
> > me with this problem? many thanks,

>
> Since there's line-wrapping, etc. in your posting, it's hard to say what's
> causing the problem, but in any case all you really need here is a pipeline:
>
> find ... | awk ... | sort ... | uniq ... |
> awk -F'.' '
> FNR == NR {
> # do_sth()
> next
> } {
> # do_other_thing()
> }
> ' file1.txt -
>
> Note the "-" sign at the end to tell awk to read stdin after reading file1.txt.
>
> Regards,
>
> Ed.


thanks, this worked. :-)

lihao
  Réponse avec citation
Vieux 29/04/2008, 20h47   #6
lihao0129@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash: process substitution not working in script

On Apr 29, 2:42 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On 2008-04-29, lihao0...@gmail.com <lihao0...@gmail.com> wrote:
>
> > ./script.sh: line 30: syntax error near unexpected token `('
> > ./script.sh: line 30: `' file1.txt <( find -type f -exec file {}
> > + | \'

>
> > I checked the man page about the process substitution which mentioned
> > the named pipe. since I am not familiar with this part, could someone
> > me with this problem? many thanks,

>
> Does your script begin with #!/bin/bash?


Thanks, if I change the shebang line from

#!/bin/sh

to

#!/bin/bash

my original script worked. Just curious since 'ls -l /bin/sh' shows

lrwxrwxrwx 1 root root 4 Apr 23 15:20 /bin/sh -> bash

I thought it's bash by default...

Best,
lihao
  Réponse avec citation
Vieux 29/04/2008, 20h50   #7
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: bash: process substitution not working in script

On Tuesday 29 April 2008 21:47, lihao0129@gmail.com wrote:

>> Does your script begin with #!/bin/bash?

>
> Thanks, if I change the shebang line from
>
> #!/bin/sh
>
> to
>
> #!/bin/bash
>
> my original script worked. Just curious since 'ls -l /bin/sh' shows
>
> lrwxrwxrwx 1 root root 4 Apr 23 15:20 /bin/sh -> bash


But bash behaves slightly differently if it's invoked with the name "sh". It
actually (tries to) run in POSIX mode, where the <(..) construct does not
exist. See the man for the details.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h37.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15356 seconds with 15 queries