Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Should test -t with no arg be supported? #1350

Open
@krader1961

Description

@krader1961

I was mildly surprised to find this block of code was not covered by a unit test since we had explicit test -t tests:

if (c2_eq(arg, '-', 't')) {
if (cp) {
long l = strtol(cp, &binop, 10);
if (*binop) return 0;
if (l > INT_MAX || l < INT_MIN) return 0;
op = (int)l;
if (shp->subshell && op == STDOUT_FILENO) return 0;
return tty_check(op);
}
// Test -t with no arguments.
tp->ap--;
if (shp->subshell) return 0;
return tty_check(STDOUT_FILENO);
}

After looking at the code I realized the code in the if (cp) block would only be executed by doing something like test -t 1 -a -t 1. The problem is that omitting the file descriptor as implied by the source code as being acceptable produces inconsistent results. Basically, this undocumented "feature" only works correctly if -t is the final, or only, term in a test expression and is missing its argument.

Note too that bundling the value (e.g., test -t1) is also silently, and incorrectly, handled.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions