|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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,"/") rintb[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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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? |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|