dash does not support multi-digit file descriptors

Bug #249620 reported by kstemen
22
This bug affects 5 people
Affects Status Importance Assigned to Milestone
dash (Debian)
Confirmed
Unknown
dash (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Binary package hint: dash

Found in dash version 0.5.4-8ubuntu1.

The POSIX specification for "Shell Command Language" at http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_07 says that multi-digit file descriptors are allowed, i.e. 10, 20, 25, etc..

The relevant part of the specification is
"The redirection operator:

[n]>&word

shall duplicate one output file descriptor from another, or shall close one. If word evaluates to one or more digits, the file descriptor denoted by n, or standard output if n is not specified, shall be made to be a copy of the file descriptor denoted by word ..."

Dash seems to only support single digit fds:
kstemen@kyle-vmserver:~$ sh 3>3.txt 9>9.txt 10>10.txt 11>11.txt
$ ls /proc/$$/fd
0 1 10 11 12 2 3 9
$ echo test >&3
$ echo test >&9
$ echo test >&10
sh: Syntax error: Bad fd number
$ echo test >&11
sh: Syntax error: Bad fd number
$

This seems to be caused by fixredir in parser.c:
void fixredir(union node *n, const char *text, int err)
    {
    TRACE(("Fix redir %s %d\n", text, err));
    if (!err)
        n->ndup.vname = NULL;

    if (is_digit(text[0]) && text[1] == '\0')
        n->ndup.dupfd = digit_val(text[0]);
    else if (text[0] == '-' && text[1] == '\0')
        n->ndup.dupfd = -1;
    else {

        if (err)
            synerror("Bad fd number");
        else
            n->ndup.vname = makename();
    }
}

Tags: udd-find
Revision history for this message
Jamie Lokier (jamie-shareable) wrote :

Confirmed.

This doesn't work either:

      exec 200>file

Neither does the sample code given in the "flock" man page:

       (
         flock -s 200
         # ... commands executed under lock ...
       ) 200>/var/lock/mylockfile

Revision history for this message
Jilles Tjoelker (jilles) wrote :

You may want this, but allowing only fd 0-9 is not a POSIX violation. XCU 2.7 Redirection says the maximum fd for redirection is implementation-defined and must be at least 9. This is sufficient for most applications.

tags: added: udd-find
Changed in dash (Debian):
status: Unknown → New
Revision history for this message
Jilles Tjoelker (jilles) wrote :

Upstream seems to have said no fix is planned: http://<email address hidden>/msg00200.html

Furthermore, I have tried this command in various other shells and it does not work in zsh, ksh93 and mksh either. (ksh93 has a different, incompatible way to use fds greater than 9.)

Therefore, what should be fixed is the man page of flock. The file descriptor should be 9, for example.

Changed in dash (Debian):
status: New → Confirmed
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in dash (Ubuntu):
status: New → Confirmed
Revision history for this message
NickW (e-launchpad-wu-lee-noodlefactory-co-uk) wrote :

Just observed this behaviour myself, although I had to google to learn the cause.

So I would also request that the error message could be more informative than this:

    exec: 200: not found

N

Revision history for this message
jwater7 (0cs935kb517wwmwa7m9428daadkyev8-mail) wrote :

One larger side effect of not supporting more fds is that the use of multi volume info script in tar fails (as in their example)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.