LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-29-2017, 01:56 PM   #1
Weapon S
Member
 
Registered: May 2011
Location: Netherlands
Distribution: Debian, Archlinux
Posts: 260
Blog Entries: 2

Rep: Reputation: 49
[Ubuntu] Process substitution prints out file descriptor?


Every time I use process substitution, it prints out the file descriptor of the temporary pipe afterwards. Simplest example (I wouldn't expect any output):
Code:
$ echo <( false )
> /dev/fd/63
I don't remember I've ever had this issue with any other Linux while using process substitution. Is there any option, command, or syntax I can use to suppress this output? Or did I just remember incorrectly?
 
Old 04-29-2017, 05:31 PM   #2
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 759

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Try cat instead of echo. Do you literally=actually get that > character displayed on the output=result line? (I don't)
Now that I've knocked this thread off of pristene ZRT status, hopefully LQgurus will come along with a detailed explanation
A web-search of "/dev/fd/63" returns somethings I remember searching for in the past, like: https://unix.stackexchange.com/quest...hich-is-a-pipe

Edit: Found MUCH BETTER! link: http://tldp.org/LDP/abs/html/process-sub.html
And, adding ThreadTitle, http://wiki.bash-hackers.org/syntax/...ion/proc_subst
Wiki has echo<(true) http://wikipedia.org/wiki/Process_substitution

But I don't have a precise&full explanation. (Interesting study tho!)
p.s. Minor 'nit': suggest adding "bash" to ThreadTitle (so viewers don't think 'krnl' e.g. )

Last edited by !!!; 04-29-2017 at 06:17 PM.
 
Old 04-29-2017, 07:21 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,555

Rep: Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088
Quote:
Originally Posted by Weapon S View Post
Code:
$ echo <( false )
> /dev/fd/63
Did you think you had redirected the output from false to the stdin of the echo command? That is not what you did. That form of process redirection sets up a file descriptor and passes an argument that is a pathname that can be opened to access that file descriptor. The echo command does not open files. It just echoes its arguments.

If you want to redirect a command's stdin as with a pipe, you can do it this way:
Code:
command1 < <( command2 )
Note the space between the two "<" characters.

I'm sure some will wonder why on Earth you would do that rather than simply writing "command2 | command1", but that construct is useful for streams other than stdin and for redirecting the stdin of loops in shell scripts:
Code:
X=0
while read Var; do
    $((X += Var))
done < <(command)
echo "Sum=$X"
If you tried to do that with "command | while read Var; do ... done", the while loop would be run in a sub-shell, and the incremented value of X would not be available outside the loop.
 
2 members found this post helpful.
Old 04-30-2017, 12:12 AM   #4
Weapon S
Member
 
Registered: May 2011
Location: Netherlands
Distribution: Debian, Archlinux
Posts: 260

Original Poster
Blog Entries: 2

Rep: Reputation: 49
Yep, I'm stupid. The actual program I had trouble with was wc (to be exact: "wc -l <( find /home/me -size -2k )" ). Then to make a minimum replication of the problem, I used echo. Echo will just print out the argument it gets, and wc will print out the file(s) it counted in at the end.
 
  


Reply

Tags
bash, file descriptor, process substitution, ubuntu


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
Process file descriptor soft limit gaurav_s Linux - Software 1 01-15-2015 06:30 AM
cygwin process substitution issue dev_linux Linux - Newbie 7 07-08-2013 08:16 AM
Bash Process Substitution joshholt Programming 4 10-11-2005 03:15 AM
process substitution jk3us Linux - Software 1 12-02-2004 04:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:49 AM.

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