Linux Debian support - Re: bad file descriptor in ksh but not in bash

This is Interesting: Free IT Magazines  
Home > Archive > Linux Debian support > April 2006 > Re: bad file descriptor in ksh but not in bash





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: bad file descriptor in ksh but not in bash
Michael Paoli

2006-04-18, 12:12 am

M=2E =C5hman wrote:
> On 12 Apr 2006 08:08:32 -0700
> "Michael Paoli" <michael1cat@yahoo.com> wrote:
> Found it in pdksh's man page:

Ah, ... good catch :-) ... and even a fairly logically place for it.
> exec [command [arg ...]]
> If no command is given except for I/O redirection, the I/O redi-
> rection is permanent and the shell is not replaced. Any file
> de- scriptors greater than 2 which are opened or dup(2)'d in
> this way are not made available to other executed commands (i.e.
> commands that are not built-in to the shell). Note that the
> Bourne shell differs here; it does pass these file descriptors
> on.

I also note my ksh(1)/pdksh(1) also includes, right below that:
(DEBIAN NOTE: when the shell is called as /bin/sh, it does pass these
file descriptors on, like the Bourne shell.)

Now, I wonder if arg0 needs to litterally be /bin/sh, or if it
suffices for arg0 to have a basename of sh or -sh, or perhaps even just
starting with one of those sets of characters in the basename portion.

Ah yes, the documentation isn't precisely correct:
$ PERL -e 'exec {q(/bin/ksh)} (q(/bin/sh),q(-c),q(exec 6>foo; sh -c
'''echo foo >&6'''));'
$ PERL -e 'exec {q(/bin/ksh)} (q(sh),q(-c),q(exec 6>foo; sh -c '''echo
foo >&6'''));'
$ PERL -e 'exec {q(/bin/ksh)} (q(-sh),q(-c),q(exec 6>foo; sh -c
'''echo foo >&6'''));'
$ PERL -e 'exec {q(/bin/ksh)} (q(-ksh),q(-c),q(exec 6>foo; sh -c
'''echo foo >&6'''));'
sh: line 1: 6: Bad file descriptor
$ PERL -e 'exec {q(/bin/ksh)} (q(/bin/ksh),q(-c),q(exec 6>foo; sh -c
'''echo foo >&6'''));'
sh: line 1: 6: Bad file descriptor
$ PERL -e 'exec {q(/bin/ksh)} (q(shooflyshoo),q(-c),q(exec 6>foo; sh -c
'''echo foo >&6'''));'
sh: line 1: 6: Bad file descriptor
$ PERL -e 'exec {q(/bin/ksh)} (q(/foo/bar/baz/sh),q(-c),q(exec 6>foo;
sh -c '''echo foo >&6'''));'
$
It looks like it probably checks for a basename portion of arg0 of sh
or -sh, with perhaps some additional possibilities.

When in doubt, test and/or use the source :-)

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com