Sponsored Content
Full Discussion: Purpose of <>
Top Forums UNIX for Dummies Questions & Answers Purpose of <> Post 302607368 by drl on Wednesday 14th of March 2012 08:43:07 AM
Old 03-14-2012
Hi.

The purpose is as noted, opens for both input and output:
Code:
Opening File Descriptors for Reading and Writing
The redirection operator

[n]<>word

causes the file whose name is the expansion of word to be opened
for both reading and writing on file descriptor n, or on file
descriptor 0 if n is not specified.  If the file does not exist,
it is created. 

-- excerpt ffom man bash

I don't recall an instance when I needed such a construct, however, it is syntactically acceptable:
Code:
#!/usr/bin/env bash

# @(#) s1	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

rm -f f
pl " Create descriptor 4 and file f, show file:"
exec 4<>f
ls -lgG f

pl " Write to f:"
echo hi >f
ls -lgG f

pl " Read from f:"
cat <f

exit 0

producing:
Code:
% ./s1

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

-----
 Create descriptor 4 and file f, show file:
-rw-r--r-- 1 0 Mar 14 12:43 f

-----
 Write to f:
-rw-r--r-- 1 3 Mar 14 12:43 f

-----
 Read from f:
hi

It may be useful for writing on stdin, but I don't see the point of that.

Perhaps someone will describe a useful situation ... cheers, drl

( edit 1: corrected for exec mis-typed as echo )
( edit 2: misspelling )

Last edited by drl; 03-14-2012 at 05:50 PM..
This User Gave Thanks to drl For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Purpose of lint in UNIX

Can Any One let me know abut the use on "lint" in UNIX...... (1 Reply)
Discussion started by: kumar_saurabh
1 Replies

2. UNIX for Dummies Questions & Answers

whats the purpose of the following script?

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)
Discussion started by: vrn
1 Replies

3. Shell Programming and Scripting

Purpose of 2>&1 in the command

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)
Discussion started by: mmunir
1 Replies

4. Filesystems, Disks and Memory

Purpose of dsi log

Hi Please explain what is dsi log? Does it stores details related to File systems? (0 Replies)
Discussion started by: student2010
0 Replies

5. UNIX for Dummies Questions & Answers

What is the purpose of 2 >&1 in crontab?

while we editing the cron at the end of the cron what is the purpose of giving 2 >&1 (4 Replies)
Discussion started by: senmak
4 Replies

6. UNIX for Dummies Questions & Answers

Purpose of /etc/cron.d

What is the purpose of /etc/cron.d? (3 Replies)
Discussion started by: proactiveaditya
3 Replies

7. UNIX for Advanced & Expert Users

Purpose of inv

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)
Discussion started by: raju4u
1 Replies

8. UNIX for Dummies Questions & Answers

exact purpose of links

please explain what is the exact purpose of hard link and soft link which is best one thanks in advance regards, surendra thota (3 Replies)
Discussion started by: tsurendra
3 Replies

9. Solaris

What is the purpose of Bind on Solaris 10?

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)
Discussion started by: jastanle84
6 Replies

10. AIX

What is the Purpose of /dev/ipldevice?

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)
Discussion started by: ksgnathan
1 Replies
getusershell(3C)					   Standard C Library Functions 					  getusershell(3C)

NAME
getusershell, setusershell, endusershell - get legal user shells SYNOPSIS
#include <unistd.h> char *getusershell(void); void setusershell(void); void endusershell(void); DESCRIPTION
The getusershell() function returns a pointer to a legal user shell as defined by the system manager in the file /etc/shells. If /etc/shells does not exist, the following locations of the standard system shells are used in its place: /bin/bash /bin/csh /bin/jsh /bin/ksh /bin/ksh93 /bin/pfcsh /bin/pfksh /bin/pfsh /bin/sh /bin/tcsh /bin/zsh /sbin/jsh /sbin/pfsh /sbin/sh /usr/bin/bash /usr/bin/csh /usr/bin/jsh /usr/bin/ksh /usr/bin/ksh93 /usr/bin/pfcsh /usr/bin/pfksh /usr/bin/pfsh /usr/bin/sh /usr/bin/tcsh /usr/bin/zsh /usr/sfw/bin/zsh /usr/xpg4/bin/sh The getusershell() function opens the file /etc/shells, if it exists, and returns the next entry in the list of shells. The setusershell() function rewinds the file or the list. The endusershell() function closes the file, frees any memory used by getusershell() and setusershell(), and rewinds the file /etc/shells. RETURN VALUES
The getusershell() function returns a null pointer on EOF. BUGS
All information is contained in memory that may be freed with a call to endusershell(), so it must be copied if it is to be saved. NOTES
Restricted shells should not be listed in /etc/shells. SunOS 5.11 1 Nov 2007 getusershell(3C)
All times are GMT -4. The time now is 04:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy