|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
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
|
|||
|
|||
|
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 ![]() |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
Yes this will do.
Code:
exec 5<&1 echo "TEST" >&5 exec 5>&- |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > BASH Scripting:using file descriptors :( |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|