-/* $OpenBSD: c_test.c,v 1.27 2019/06/28 13:34:59 deraadt Exp $ */
+/* $OpenBSD: c_test.c,v 1.28 2023/06/10 07:24:21 op Exp $ */
/*
* test(1); version 7-like -- author Erik Baalbergen
}
if (argc == 1) {
opnd1 = (*te.getopnd)(&te, TO_NONOP, 1);
- /* Historically, -t by itself test if fd 1
- * is a file descriptor, but POSIX says its
- * a string test...
- */
- if (!Flag(FPOSIX) && strcmp(opnd1, "-t") == 0)
- break;
res = (*te.eval)(&te, TO_STNZE, opnd1,
NULL, 1);
if (invert & 1)
case TO_FILGZ: /* -s */
return stat(opnd1, &b1) == 0 && b1.st_size > 0L;
case TO_FILTT: /* -t */
- if (opnd1 && !bi_getn(opnd1, &res)) {
+ if (!bi_getn(opnd1, &res)) {
te->flags |= TEF_ERROR;
- res = 0;
- } else {
- /* generate error if in FPOSIX mode? */
- res = isatty(opnd1 ? res : 0);
+ return 0;
}
- return res;
+ return isatty(res);
case TO_FILUID: /* -O */
return stat(opnd1, &b1) == 0 && b1.st_uid == ksheuid;
case TO_FILGID: /* -G */
ptest_getopnd(Test_env *te, Test_op op, int do_eval)
{
if (te->pos.wp >= te->wp_end)
- return op == TO_FILTT ? "1" : NULL;
+ return NULL;
return *te->pos.wp++;
}
-.\" $OpenBSD: ksh.1,v 1.218 2022/12/26 17:45:27 jmc Exp $
+.\" $OpenBSD: ksh.1,v 1.219 2023/06/10 07:24:21 op Exp $
.\"
.\" Public Domain
.\"
-.Dd $Mdocdate: December 26 2022 $
+.Dd $Mdocdate: June 10 2023 $
.Dt KSH 1
.Os
.Sh NAME
alias a='for ' i='j'
a i in 1 2; do echo i=$i j=$j; done
.Ed
-.It
-.Ic test .
-In POSIX mode, the expression
-.Sq Fl t
-(preceded by some number of
-.Sq \&!
-arguments) is always true as it is a non-zero length string;
-in non-POSIX mode, it tests if file descriptor 1 is a
-.Xr tty 4
-(i.e. the
-.Ar fd
-argument to the
-.Fl t
-test may be left out and defaults to 1).
.El
.Ss Strict Bourne shell mode
When the
.It Fl s Ar file
.Ar file
is not empty.
-.It Fl t Op Ar fd
+.It Fl t Ar fd
File descriptor
.Ar fd
is a
.Xr tty 4
device.
-If the
-.Ic posix
-option is not set,
-.Ar fd
-may be left out, in which case it is taken to be 1 (the behaviour differs due
-to the special POSIX rules described above).
.It Fl u Ar file
.Ar file Ns 's
mode has the setuid bit set.