document somewhat surprising behaviour

12:58⎜<gps23:#ksh> someone please tell me why:   code=1; if [ "code" -eq 1 ] returns true
13:10⎜<mira|AO:#ksh> hm but I see the problem
13:10⎜<mira|AO:#ksh> code=1; x=code; [ "$x" -eq 1 ]
13:10⎜<mira|AO:#ksh> this is indeed unexpected
13:10⎜«pgas:#ksh» gps23: code=1+1;[ "code" -eq 2 ] && echo true #also works
as of now, we consider
13:13⎜«pgas:#ksh» gps23: when you use -eq there is something like an implicit $(( )) around the
     ⎜    arguments
13:14⎜«pgas:#ksh» [ code -eq 1 ] is the same as [ $((code)) -eq 1 ]
to be documented.
This commit is contained in:
tg 2009-03-23 12:15:33 +00:00
parent a8e3154b7a
commit c37c7aea61

7
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.151 2009/03/22 18:09:17 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.152 2009/03/23 12:15:33 tg Exp $
.\" $OpenBSD: ksh.1,v 1.128 2009/03/06 12:28:36 jmc Exp $ .\" $OpenBSD: ksh.1,v 1.128 2009/03/06 12:28:36 jmc Exp $
.\"- .\"-
.\" Try to make GNU groff and AT&T nroff more compatible .\" Try to make GNU groff and AT&T nroff more compatible
@ -30,7 +30,7 @@
.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 .el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
.. ..
.\"- .\"-
.Dd $Mdocdate: March 22 2009 $ .Dd $Mdocdate: March 23 2009 $
.Dt MKSH 1 .Dt MKSH 1
.Os MirBSD .Os MirBSD
.Sh NAME .Sh NAME
@ -3859,6 +3859,9 @@ expr \-a expr Logical AND.
( expr ) Grouping. ( expr ) Grouping.
.Ed .Ed
.Pp .Pp
Note that a number actually may be an arithmetic expression, such as
a mathematical term or the name of an integer variable.
.Pp
Note that some special rules are applied (courtesy of POSIX) Note that some special rules are applied (courtesy of POSIX)
if the number of if the number of
arguments to arguments to