home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!ftpbox!mothost!merlin.dev.cdx.mot.com!fendahl.dev.cdx.mot.com!mcook
- From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
- Subject: Re: Korn shell and file descriptors
- Message-ID: <mcook.714794558@fendahl.dev.cdx.mot.com>
- Sender: news@merlin.dev.cdx.mot.com (USENET News System)
- Nntp-Posting-Host: fendahl.dev.cdx.mot.com
- Organization: Motorola Codex, Canton, Massachusetts
- References: <1548@tetra.co.uk>
- Date: Wed, 26 Aug 1992 02:02:38 GMT
- Lines: 32
-
- dave@tetra.co.uk (David Sussman) writes:
-
- >I have an interesting Korn Shell problem. I have a script containing:
-
- > echo stream 1 >&1
- > echo stream 2 >&2
- > echo stream 3 >&3
- > echo stream 4 >&4
-
- >Under the Bourne Shell this works ok, but the Korn Shell produces:
-
- > stream 1
- > stream 2
- > ./ksh[3]: 3: bad file unit number
- > ./ksh[4]: 4: bad file unit number
-
- >Why?
-
- When you do
-
- echo stream 3 >&3
-
- the shell does a dup2(3,1) for you, which means close file descriptor 1, and
- then make it point at whatever file descriptor 3 is pointing at. If file
- descriptor 3 isn't currently open, dup2 fails. The Bourne shell was probably
- ignoring the failure; ksh tells you.
-
- You can test to see whether file descriptor 3 is open like this:
-
- (exec>&3) 2>/dev/null || echo "3 is not open"
-
- Michael.
-