LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 10-03-2009, 06:02 AM   #16
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208

Quote:
Originally Posted by konsolebox View Post
I learned this hack when i was trying to simplify my program.

Code:
echo >(do something)
should explain everything.
>() commands actually creates a subprocess and links it to a file (maybe named pipes, etc.).. then we just use exec normally to use the file.

Edit: The result should be just like having two processes (the parent and the subprocess) work with a pipe.
Thanks I think I've got it now. Is this correct:

The exec 4> > (<commands>) only defines fd 4; it is not instantiated until fd 4 is used by the echo <string> >4 when the subshell is created with its stdin already loaded.
 
Old 10-03-2009, 06:22 AM   #17
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by catkin View Post
Thanks I think I've got it now. Is this correct:

The exec 4> > (<commands>) only defines fd 4; it is not instantiated until fd 4 is used by the echo <string> >4 when the subshell is created with its stdin already loaded.
Depends on the implementation of the shell but I think it's most likely that before a data is sent to a FD, or before 'echo', everything is already set and fd 4 is already instantiated. That's what I think since it would probably be inconsistent if the shell acts differently. What's the use of a closer statement (exec n>&-) in that case?
Note that a pipe still works even though a data is not sent.

Code:
: | bash '{ echo a; read; echo $REPLY; }'
.. i think will still print 'a'

Sorry if my explanation is a bit cloudy.

edit: remember that after >(command) expands to a path, the subprocess that was created there just waits to another process to use its pipe. We can therefore conclude here that >(command) and exec in 'exec 4> >(command)' is not directly dependent to each other.

try to save the expanded value of >(command) to a variable and see if it works:
Code:
PIPEFILE=>(command)
echo pipefile is $PIPEFILE
exec 4> $PIPEFILE
: do something
exec 4>&-
if PIPEFILE=>(command) does not expand as expected try to use eval
Code:
eval PIPEFILE=>(command)

Last edited by konsolebox; 10-03-2009 at 06:36 AM.
 
  


Reply



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
bash script in background - awk and send email noir911 Programming 4 03-22-2009 09:46 PM
how to stop parsing shell variables in bash script inside cat area? jackandking Linux - Newbie 2 03-10-2009 06:44 AM
Bash script hangs upon starting another script in the background masea2 Linux - Software 4 11-13-2006 05:18 AM
Suse's Ivtv And Lirc Don't Work, cat: /dev/video: No such device lagu2653 SUSE / openSUSE 0 12-09-2005 10:09 AM
How to run a bash command in the background from perl script professorfrink Programming 3 11-13-2003 03:02 PM

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

All times are GMT -5. The time now is 06:45 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