Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (2) </ [1] 2 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: No Bash Command Substitution?!, Missing /dev/fd/ files< Next Oldest | Next Newest >
chaostic Offline





Group: Members
Posts: 328
Joined: Mar. 2005
Posted: Jan. 07 2008,06:48 QUOTE

Using 3.4.4, it seems that command substitution doesn't work in DSL.

Code Sample

dsl@ttyp1[dsl]$ sudo cat Events >( grep -i "Linux" - > test.txt )
07:19:DSL 1.3.1 Released
08:02:DSL 1.4 Released.
08:09:Linux World
08:10:Linux World
08:11:Linux World
10:31:Halloween
cat: /dev/fd/63: No such file or directory


sudo, or it would hang at the end of cat, because it can not access the non-existent file.

Can't sudo mkfifo /dev/fd/63, or touch /dev/fd/63

/dev/fd points to /proc/self/fd/
/proc/self points to /proc/n/ where n changes on almost every command

Basically, there is no fifos at /dev/fd/xx and command substitution won't work.

How can I create them, or can they be added for the next maintence 3.4.9
Back to top
Profile PM 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Jan. 07 2008,15:45 QUOTE

I'm not sure what you're trying to do... but you could try something like
Code Sample
$ cat Events | grep -i "Linux" > test.txt
or if you need stdout as well
Code Sample
$ cat Events | grep -i "Linux" | tee test.txt
Also, I don't think you're trying to do command substitution.

EDIT: manpage says process substitution.  Bash will use temporary files if /dev/fd/?? (i.e. `echo <(true)` ) doesn't exist... so your syntax is wrong?  If you need to use it, maybe try something like
Code Sample
$ grep -i "Linux" <(cat Events) > test.txt #redundant
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Jan. 07 2008,16:45 QUOTE

For bash-specific command substitution, the opening parenthesis is preceded by a $:
$(grep -i "Linux" -)
You can also use backticks for compatibility with other shells:
`grep -i "Linux" -`

I think the first example from ^thehatsrule^ is most logical though.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Jan. 07 2008,17:18 QUOTE

mikshaw: using - will require something from stdin, and using command substitution only provides output... so wouldn't that just stall?
Back to top
Profile PM 
chaostic Offline





Group: Members
Posts: 328
Joined: Mar. 2005
Posted: Jan. 08 2008,06:17 QUOTE

Well, I would need the command substitution to do:
Code Sample

cat /dev/ptyu1 | fgrep --line-buffered -e "New Title" -e "Icy-Name" -e "icy-url" | sed -e /"access_http debug: "/s/// -e '/Icy-Name/i\
--
' -e /"Meta-Info: icy-url"/s//"Icy-Url"/ -e /"New Title="/s//"Now Playing: "/ | tee >(grep --line-buffered "Icy-Name" | sed -e /"Icy-Name"/s/// > CurrentStation.txt) >(grep --line-buffered "Now Playing" | sed -e /"Now Playing"/s///) >(nc)


or

Code Sample
command1 | tee >(command2) >(command3) >(command4) | command5


Or in simpler terms, allow for multiple programs writing multiple files from the same base file read, which when using pipes, named pipes, or pseudo-terminals needs to be done like this since only one program can read or write to it at a time.

Edit: The example I used in the first post was just that, an example. :/
Back to top
Profile PM 
8 replies since Jan. 07 2008,06:48 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (2) </ [1] 2 >/
reply to topic new topic new poll
Quick Reply: No Bash Command Substitution?!

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code