If that were even valid, what would it accomplish? The instant you open a file with >, you truncate it, leaving nothing to read.
I have used similar syntax used in bash to open device files:
Code:
exec 5<>/dev/ttyUSB1
...to open a serial port for instance. Then I could echo asdf >&5 and read <&5 without reopening and re-closing the serial port every call. But I believe that's BASH-only syntax, and only useful in very specific circumstances.
Last edited by Corona688; 03-14-2012 at 01:13 PM..
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
The <> re-direction operator is also available in ksh and zsh.
The serial port example makes it useful ... cheers, drl
---------- Post updated at 12:48 ---------- Previous update was at 12:27 ----------
Hi.
Associating a file descriptor with an existing file does not destroy it:
Code:
#!/usr/bin/env bash
# @(#) s3 Demonstrate <> re-direction operator.
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && . $C
echo first time > f
pl " Initial content of file f:"
cat f
pl " Associate descriptor 4 with file f, show file:"
exec 4<>f
cat f
ls -lgG f
read -u 4 line
pe " variable line read from FD 4 as \"$line\""
pl " Write to f:"
echo hi >f
ls -lgG f
pl " Read from f:"
cat <f
exit 0
producing:
Code:
% ./s3
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.8 (lenny)
bash GNU bash 3.2.39
-----
Initial content of file f:
first time
-----
Associate descriptor 4 with file f, show file:
first time
-rw-r--r-- 1 11 Mar 14 12:46 f
variable line read from FD 4 as "first time"
-----
Write to f:
-rw-r--r-- 1 3 Mar 14 12:46 f
-----
Read from f:
hi
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
The construct <>filename seems to work with ksh:
Code:
#!/usr/bin/env ksh
#!/usr/bin/env zsh
#!/usr/bin/env bash
# @(#) s4 Demonstrate <> re-direction operator.
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && . $C
echo first time > f
pl " Initial content of file f:"
cat f
pl " Associate descriptor with file f, show file:"
# exec 4<>f
<>f
cat f
ls -lgG f
read -u 0 line
pe " variable line read from FD as \"$line\""
pl " Write to f:"
echo hi >f
ls -lgG f
pl " Read from f:"
cat <f
exit 0
producing:
Code:
./s4
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.32-5-686, i686
Distribution : Debian GNU/Linux 6.0.3 (squeeze)
ksh 93s+
-----
Initial content of file f:
first time
-----
Associate descriptor with file f, show file:
first time
-rw-r----- 1 11 Mar 14 16:00 f
xx
variable line read from FD as "xx"
-----
Write to f:
-rw-r----- 1 3 Mar 14 16:00 f
-----
Read from f:
hi
I needed to enter something from the keyboard for the read -u. So the intent seems OK, but perhaps a problem with bash ... cheers, dr;
Hi,
Anyone, please explain the purpose of /dev/ipldevice in AIX .. it would be a problem if there is no /dev/ipldevice while booting.
Regards,
Siva (1 Reply)
I'm new to Solaris and Linux and I was wondering if someone could explain to me in simple terms what the process Bind is on Solaris 10? Thanks, in advance. (6 Replies)
Hi All
Can anybody tell me what is the purpose of inv in the below command.
ftp -inv $RFTPSERVER /temp/te.txt << EOF
and << its stands for what..
Thanks (1 Reply)
Can any body kindly tell me what is the purpose of 2>&1 in the following commands.
nohup ./append_import.sh 1 > import1.out 2>&1 < /dev/null &
nohup ./append_import.sh 2 > import2.out 2>&1 < /dev/null & (1 Reply)
whats the purpose of the following script? who could run it? To what is the script refering that exceeds 75%? The mailbox?
What does sed 's/%//' do? (1 Reply)