evaluate more on [ X"$foo" = X"bar" ]
use ksh features [[ $foo = bar ]] and print instead of echo
This commit is contained in:
parent
955d52cb21
commit
51053f03f5
58
ksh.1tbl
58
ksh.1tbl
@ -1,4 +1,4 @@
|
|||||||
.\" $MirBSD: src/bin/ksh/ksh.1tbl,v 2.4 2004/12/13 19:18:01 tg Exp $
|
.\" $MirBSD: src/bin/ksh/ksh.1tbl,v 2.5 2004/12/13 19:36:27 tg Exp $
|
||||||
.\" $OpenBSD: ksh.1tbl,v 1.79 2004/12/04 07:05:13 jaredy Exp $
|
.\" $OpenBSD: ksh.1tbl,v 1.79 2004/12/04 07:05:13 jaredy Exp $
|
||||||
.\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $
|
.\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $
|
||||||
.\"
|
.\"
|
||||||
@ -607,7 +607,7 @@ For historical reasons, open and close braces may be used instead of
|
|||||||
and
|
and
|
||||||
.Ic esac
|
.Ic esac
|
||||||
(e.g.,
|
(e.g.,
|
||||||
.Ic case $foo { *) echo bar; } ) .
|
.Ic case $foo { *) print bar; } ) .
|
||||||
The exit status of a
|
The exit status of a
|
||||||
.Ic case
|
.Ic case
|
||||||
statement is that of the executed
|
statement is that of the executed
|
||||||
@ -639,7 +639,7 @@ For historical reasons, open and close braces may be used instead of
|
|||||||
and
|
and
|
||||||
.Ic done
|
.Ic done
|
||||||
(e.g.,
|
(e.g.,
|
||||||
.Ic for i\&; { echo $i; } ) .
|
.Ic for i\&; { print $i; } ) .
|
||||||
The exit status of a
|
The exit status of a
|
||||||
.Ic for
|
.Ic for
|
||||||
statement is the last exit status of
|
statement is the last exit status of
|
||||||
@ -728,7 +728,7 @@ For historical reasons, open and close braces may be used instead of
|
|||||||
and
|
and
|
||||||
.Ic done
|
.Ic done
|
||||||
(e.g.,
|
(e.g.,
|
||||||
.Ic select i; { echo $i; } ) .
|
.Ic select i; { print $i; } ) .
|
||||||
The exit status of a
|
The exit status of a
|
||||||
.Ic select
|
.Ic select
|
||||||
statement is zero if a
|
statement is zero if a
|
||||||
@ -1079,8 +1079,8 @@ This should be fixed soon.
|
|||||||
.Pp
|
.Pp
|
||||||
Arithmetic substitutions are replaced by the value of the specified expression.
|
Arithmetic substitutions are replaced by the value of the specified expression.
|
||||||
For example, the command
|
For example, the command
|
||||||
.Ic echo $((2+3*4))
|
.Ic print $((2+3*4))
|
||||||
prints 14.
|
displays 14.
|
||||||
See
|
See
|
||||||
.Sx Arithmetic expressions
|
.Sx Arithmetic expressions
|
||||||
for a description of an expression.
|
for a description of an expression.
|
||||||
@ -2564,7 +2564,7 @@ loop
|
|||||||
.Ic alias a='for ' i='j'
|
.Ic alias a='for ' i='j'
|
||||||
.It
|
.It
|
||||||
.Xo
|
.Xo
|
||||||
.Ic a i in 1 2; do echo i=$i j=$j;
|
.Ic a i in 1 2; do print i=$i j=$j;
|
||||||
.Ic done
|
.Ic done
|
||||||
.Xc
|
.Xc
|
||||||
.El
|
.El
|
||||||
@ -3587,20 +3587,6 @@ and
|
|||||||
statements.
|
statements.
|
||||||
The following basic expressions are available:
|
The following basic expressions are available:
|
||||||
.Bl -tag -width 17n
|
.Bl -tag -width 17n
|
||||||
.It Ar str
|
|
||||||
.Ar str
|
|
||||||
has non-zero length.
|
|
||||||
Note that there is the potential for problems if
|
|
||||||
.Ar str
|
|
||||||
turns out to be an operator (e.g.,
|
|
||||||
.Fl r ) .
|
|
||||||
It is generally better to use a test like
|
|
||||||
.Sm off
|
|
||||||
.Ic \&[\ X\&" Ar str Ic \&" Ic \ \&]
|
|
||||||
.Sm on
|
|
||||||
instead (double quotes are used in case
|
|
||||||
.Ar str
|
|
||||||
contains spaces or file globbing characters).
|
|
||||||
.It Fl r Ar file
|
.It Fl r Ar file
|
||||||
.Ar file
|
.Ar file
|
||||||
exists and is readable.
|
exists and is readable.
|
||||||
@ -3708,21 +3694,22 @@ rules described below).
|
|||||||
is not empty (has non-zero length).
|
is not empty (has non-zero length).
|
||||||
Note that there is the potential for problems if
|
Note that there is the potential for problems if
|
||||||
.Ar string
|
.Ar string
|
||||||
turns out to be an operator (e.g.,
|
turns out to be an operator (e.g.
|
||||||
.Fl r ) .
|
.Fl r ) .
|
||||||
It is generally better to use a test like
|
It is generally better to use a test like
|
||||||
|
.No ( Ns Nm sh )
|
||||||
|
.Bk -words
|
||||||
.Sm off
|
.Sm off
|
||||||
.Ic \&[\ X\&" Ar string Ic \&" Ic \ \&]
|
.Ic \&[\ X\&" Ar string Ic \&" Ic \ \&]
|
||||||
.Sm on
|
.Sm on
|
||||||
or (on
|
.Ek
|
||||||
.Nm ksh
|
.No or ( Ns Nm ksh )
|
||||||
only)
|
.Bk -words
|
||||||
.Sm off
|
.Ic \&[[ Fl n Ar string Ic \&]]
|
||||||
.Ic \&[\&[ Fl n Ar string Ic \ \&]\&]
|
.Ek
|
||||||
.Sm on
|
|
||||||
instead (double quotes are used in case
|
instead (double quotes are used in case
|
||||||
.Ar string
|
.Ar string
|
||||||
contains spaces or file globbing characters).
|
contains spaces or globbing characters).
|
||||||
.It Fl z Ar string
|
.It Fl z Ar string
|
||||||
.Ar string
|
.Ar string
|
||||||
is empty.
|
is empty.
|
||||||
@ -3800,7 +3787,9 @@ if the first argument is a unary operator, including an unstripped
|
|||||||
.Pp
|
.Pp
|
||||||
.Sy Note:
|
.Sy Note:
|
||||||
A common mistake is to use
|
A common mistake is to use
|
||||||
|
.Bk -words
|
||||||
.Ic if \&[ $foo = bar \&]
|
.Ic if \&[ $foo = bar \&]
|
||||||
|
.Ek
|
||||||
which fails if parameter
|
which fails if parameter
|
||||||
.Ic foo
|
.Ic foo
|
||||||
is
|
is
|
||||||
@ -3812,7 +3801,14 @@ characters), or if it is a unary operator like
|
|||||||
or
|
or
|
||||||
.Sq Fl n .
|
.Sq Fl n .
|
||||||
Use tests like
|
Use tests like
|
||||||
|
.No ( Ns Nm sh )
|
||||||
|
.Bk -words
|
||||||
.Ic if \&[ \&"X$foo\&" = Xbar \&]
|
.Ic if \&[ \&"X$foo\&" = Xbar \&]
|
||||||
|
.Ek
|
||||||
|
.No or ( Ns Nm ksh )
|
||||||
|
.Bk -words
|
||||||
|
.Ic if \&[[ \&$foo = bar \&]]
|
||||||
|
.Ek
|
||||||
instead.
|
instead.
|
||||||
.It Xo Ic time Op Fl p
|
.It Xo Ic time Op Fl p
|
||||||
.Op Ar pipeline
|
.Op Ar pipeline
|
||||||
@ -5304,7 +5300,7 @@ development team at
|
|||||||
Please include the version of
|
Please include the version of
|
||||||
.Nm
|
.Nm
|
||||||
.Po
|
.Po
|
||||||
.Ic echo $KSH_VERSION
|
.Ic print $KSH_VERSION
|
||||||
shows it
|
shows it
|
||||||
.Pc ,
|
.Pc ,
|
||||||
the machine, operating system, and compiler you are using and how you built
|
the machine, operating system, and compiler you are using and how you built
|
||||||
@ -5329,7 +5325,7 @@ script).
|
|||||||
.Pp
|
.Pp
|
||||||
By the way, the most frequently reported bug is:
|
By the way, the most frequently reported bug is:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
$ echo hi | read a; echo $a # Does not print hi
|
$ print hi | read a; print $a # Does not show hi
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
|
Loading…
Reference in New Issue
Block a user