LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2005, 02:22 PM   #1
joshholt
LQ Newbie
 
Registered: Sep 2005
Posts: 1

Rep: Reputation: 0
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
 
Old 09-30-2005, 02:25 PM   #2
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 10-02-2005, 06:58 AM   #3
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Have you tried piping the echo into the sed?
Code:
VAR=$(echo "$x" | sed 's/<Computer comp="\(.*\)" user="\(.*\)" password="\(.*\)">/\1 \2 \3/')
 
Old 10-11-2005, 02:04 AM   #4
paige_dchamred1
LQ Newbie
 
Registered: Oct 2005
Posts: 1

Rep: Reputation: 0
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.
 
Old 10-11-2005, 04:15 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 233Reputation: 233Reputation: 233
The clue is:

Code:
#!/bin/sh

cat <(echo hello) <(echo world)
This construct is not valid in bourne shell.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can bash create a detached process? GN9500 Linux - Newbie 4 07-08-2012 08:28 PM
bash assignments of commands substitution p0rtius Programming 6 07-03-2005 07:41 PM
Bash - background process and exit ?? michael_util Programming 4 01-05-2005 12:03 PM
process substitution jk3us Linux - Software 1 12-02-2004 05:34 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 02:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration