SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old June 8th, 2004, 02:30 AM
funkymunky funkymunky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 12 funkymunky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy BASH Scripting:using file descriptors :(

hi!

how are file descriptors used in BASH?
the format for assigning a file descriptor to a particular file is [n]<>file, right?

now, suppose i do this:
$ : [4]<>temp

how do i use it subsequently? i mean, suppose i want to redirect the o/p of a particular command to temp, how do i do it using its file descriptor?
this doesnt work either:
echo "hello" >&4

where am i going wrong?? kindly help

thanx in advance

Reply With Quote
  #2  
Old June 21st, 2004, 12:58 AM
murugesan murugesan is offline
Dinesh_P_V
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: India
Posts: 256 murugesan New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 11 h 38 m
Reputation Power: 0
Send a message via Yahoo to murugesan
The following script reads the first line from the file dins.c and echoes the first line read from that file.

Code:
#!/bin/sh
exec 5<> dins.c # Open "dins.c" and assign fd 5 to it
read <&5          # Read the first line
exec 5>&-        # Close fd 5
echo $REPLY


HTH

Reply With Quote
  #3  
Old June 21st, 2004, 02:02 AM
funkymunky funkymunky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 12 funkymunky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

thanx for your reply...

now , suppose i want to copy the std o/p stream to a file descriptor...so that whatever is to be printed on to the std o/p goes to that file instead..

will exec 5<&1 work?

and then after the work is done, how would i restore things back so that the std o/p again goes to the screen?

thanx in anticipation

Mayank

Reply With Quote
  #4  
Old June 21st, 2004, 02:18 AM
murugesan murugesan is offline
Dinesh_P_V
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: India
Posts: 256 murugesan New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 11 h 38 m
Reputation Power: 0
Send a message via Yahoo to murugesan
Yes this will do.

Code:
exec 5<&1
echo "TEST" >&5
exec 5>&-

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > BASH Scripting:using file descriptors :(


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway