LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash Process Substitution (https://www.linuxquestions.org/questions/programming-9/bash-process-substitution-368523/)

joshholt 09-30-2005 01:22 PM

Bash Process Substitution
 
I have a script like so:


#!/bin/bash
while read x
do
sed -e 's/<Computer comp="\(.*\)" user="\(.*\)" password="\(.*\)">/\1 \2 \3/' <(echo -e "$x")
done < <(cat archive_app.conf |grep -v '^#\\|^$')


the script fails where I try to use process substitution
yet this work from the command line .... now being that the command line and the script are both interpted via bash
I would assume that this should work.

the error that I get is this:

blah.sh: line 5: syntax error near unexpected token `('
blah.sh: line 5: `sed -e 's/<Computer comp="\(.*\)" user="\(.*\)" password="\(.*\)">/\1 \2 \3/' <(echo -e "$x") '

I know that this is the case for when I take away the process substitutions I don't get the errors

You help is very much welcomed.

Thanks,
Josh Holt

XavierP 09-30-2005 01:25 PM

Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

eddiebaby1023 10-02-2005 05:58 AM

Have you tried piping the echo into the sed?
Code:

VAR=$(echo "$x" | sed 's/<Computer comp="\(.*\)" user="\(.*\)" password="\(.*\)">/\1 \2 \3/')

paige_dchamred1 10-11-2005 01:04 AM

Re: Bash Process Substitution
 
Quote:

Originally posted by joshholt
I have a script like so:


#!/bin/bash
while read x
do
sed -e 's/<Computer comp="\(.*\)" user="\(.*\)" password="\(.*\)">/\1 \2 \3/' <(echo -e "$x")
done < <(cat archive_app.conf |grep -v '^#\\|^$')


the script fails where I try to use process substitution
yet this work from the command line .... now being that the command line and the script are both interpted via bash
I would assume that this should work.

the error that I get is this:

blah.sh: line 5: syntax error near unexpected token `('
blah.sh: line 5: `sed -e 's/<Computer comp="\(.*\)" user="\(.*\)" password="\(.*\)">/\1 \2 \3/' <(echo -e "$x") '

I know that this is the case for when I take away the process substitutions I don't get the errors

You help is very much welcomed.

Thanks,
Josh Holt


I have the same problem ...

On the command line:

$ cat <(echo hello) <(echo world)
hello
world

Inside script file:
#!/bin/sh

cat <(echo hello) <(echo world)


When I execute the script I get:

$ ./proc_sub.sh
./proc_sub.sh: line 3: syntax error near unexpected token `('
./proc_sub.sh: line 3: `cat <(echo hello) <(echo world)'


I am currently using the bash for cygwin:

GNU bash, version 3.00.16(11)-release (i686-pc-cygwin)
Copyright (C) 2004 Free Software Foundation, Inc.

bigearsbilly 10-11-2005 03:15 AM

The clue is:

Code:

#!/bin/sh

cat <(echo hello) <(echo world)

This construct is not valid in bourne shell.


All times are GMT -5. The time now is 10:30 PM.