* rename "set -o posix" (FPOSIX) to "set -o sh" (FSH) because it's not

just a "somewhat more POSIX" but also a "/bin/sh legacy kludge" mode
* consistently capitalise POSIX and SUSv3/SUSv4 (same as AT&T ksh) and
  Bourne shell
This commit is contained in:
tg 2009-10-02 18:08:37 +00:00
parent 2ea131ab1f
commit 33b9f8b666
11 changed files with 205 additions and 202 deletions

330
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.314 2009/10/02 17:05:01 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.315 2009/10/02 18:08:31 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -25,7 +25,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh # http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R39 2009/09/29 @(#)MIRBSD KSH R39 2009/10/02
description: description:
Check version of shell. Check version of shell.
stdin: stdin:
@ -36,7 +36,7 @@ name: selftest-1
description: description:
Regression test self-testing Regression test self-testing
stdin: stdin:
print ${foo:-baz} echo ${foo:-baz}
expected-stdout: expected-stdout:
baz baz
--- ---
@ -45,7 +45,7 @@ description:
Regression test self-testing Regression test self-testing
env-setup: !foo=bar! env-setup: !foo=bar!
stdin: stdin:
print ${foo:-baz} echo ${foo:-baz}
expected-stdout: expected-stdout:
bar bar
--- ---
@ -54,7 +54,7 @@ description:
Regression test self-testing Regression test self-testing
env-setup: !ENV=fnord! env-setup: !ENV=fnord!
stdin: stdin:
print "<$ENV>" echo "<$ENV>"
expected-stdout: expected-stdout:
<fnord> <fnord>
--- ---
@ -275,29 +275,29 @@ description:
Check if unsigned arithmetics work Check if unsigned arithmetics work
stdin: stdin:
# signed vs unsigned # signed vs unsigned
print x1 $((-1)) $((#-1)) echo x1 $((-1)) $((#-1))
# calculating # calculating
typeset -i vs typeset -i vs
typeset -Ui vu typeset -Ui vu
vs=4123456789; vu=4123456789 vs=4123456789; vu=4123456789
print x2 $vs $vu echo x2 $vs $vu
(( vs %= 2147483647 )) (( vs %= 2147483647 ))
(( vu %= 2147483647 )) (( vu %= 2147483647 ))
print x3 $vs $vu echo x3 $vs $vu
vs=4123456789; vu=4123456789 vs=4123456789; vu=4123456789
(( # vs %= 2147483647 )) (( # vs %= 2147483647 ))
(( # vu %= 2147483647 )) (( # vu %= 2147483647 ))
print x4 $vs $vu echo x4 $vs $vu
# make sure the calculation does not change unsigned flag # make sure the calculation does not change unsigned flag
vs=4123456789; vu=4123456789 vs=4123456789; vu=4123456789
print x5 $vs $vu echo x5 $vs $vu
# short form # short form
print x6 $((# vs % 2147483647)) $((# vu % 2147483647)) echo x6 $((# vs % 2147483647)) $((# vu % 2147483647))
# array refs # array refs
set -A va set -A va
va[1975973142]=right va[1975973142]=right
va[4123456789]=wrong va[4123456789]=wrong
print x7 ${va[#4123456789%2147483647]} echo x7 ${va[#4123456789%2147483647]}
expected-stdout: expected-stdout:
x1 -1 4294967295 x1 -1 4294967295
x2 -171510507 4123456789 x2 -171510507 4123456789
@ -312,20 +312,20 @@ description:
Check if arithmetics are 32 bit Check if arithmetics are 32 bit
stdin: stdin:
# signed vs unsigned # signed vs unsigned
print x1 $((-1)) $((#-1)) echo x1 $((-1)) $((#-1))
# calculating # calculating
typeset -i vs typeset -i vs
typeset -Ui vu typeset -Ui vu
vs=2147483647; vu=2147483647 vs=2147483647; vu=2147483647
print x2 $vs $vu echo x2 $vs $vu
let vs++ vu++ let vs++ vu++
print x3 $vs $vu echo x3 $vs $vu
vs=4294967295; vu=4294967295 vs=4294967295; vu=4294967295
print x4 $vs $vu echo x4 $vs $vu
let vs++ vu++ let vs++ vu++
print x5 $vs $vu echo x5 $vs $vu
let vs++ vu++ let vs++ vu++
print x6 $vs $vu echo x6 $vs $vu
expected-stdout: expected-stdout:
x1 -1 4294967295 x1 -1 4294967295
x2 2147483647 2147483647 x2 2147483647 2147483647
@ -372,7 +372,7 @@ name: bksl-nl-ign-4
description: description:
Check interaction of aliases, single quotes and here-documents Check interaction of aliases, single quotes and here-documents
with backslash-newline with backslash-newline
(don't know what posix has to say about this) (don't know what POSIX has to say about this)
stdin: stdin:
a=2 a=2
alias x='echo hi alias x='echo hi
@ -395,7 +395,7 @@ expected-stdout:
name: bksl-nl-ign-5 name: bksl-nl-ign-5
description: description:
Check what happens with backslash at end of input Check what happens with backslash at end of input
(the old bourne shell trashes them; so do we) (the old Bourne shell trashes them; so do we)
stdin: ! stdin: !
echo `echo foo\\`bar echo `echo foo\\`bar
echo hi\ echo hi\
@ -595,7 +595,7 @@ name: bksl-nl-9
description: description:
Check that \ at the end of an alias is collapsed when followed Check that \ at the end of an alias is collapsed when followed
by a newline by a newline
(don't know what posix has to say about this) (don't know what POSIX has to say about this)
stdin: stdin:
alias x='echo hi\' alias x='echo hi\'
x x
@ -3897,7 +3897,7 @@ description:
Check if typeset, export, and readonly work Check if typeset, export, and readonly work
stdin: stdin:
{ {
print FNORD-0 echo FNORD-0
FNORD_A=1 FNORD_A=1
FNORD_B=2 FNORD_B=2
FNORD_C=3 FNORD_C=3
@ -3909,21 +3909,21 @@ stdin:
integer FNORD_E FNORD_F FNORD_G FNORD_H integer FNORD_E FNORD_F FNORD_G FNORD_H
export FNORD_C FNORD_D FNORD_G FNORD_H export FNORD_C FNORD_D FNORD_G FNORD_H
readonly FNORD_B FNORD_D FNORD_F FNORD_H readonly FNORD_B FNORD_D FNORD_F FNORD_H
print FNORD-1 echo FNORD-1
export export
print FNORD-2 echo FNORD-2
export -p export -p
print FNORD-3 echo FNORD-3
readonly readonly
print FNORD-4 echo FNORD-4
readonly -p readonly -p
print FNORD-5 echo FNORD-5
typeset typeset
print FNORD-6 echo FNORD-6
typeset -p typeset -p
print FNORD-7 echo FNORD-7
typeset - typeset -
print FNORD-8 echo FNORD-8
} | fgrep FNORD } | fgrep FNORD
expected-stdout: expected-stdout:
FNORD-0 FNORD-0
@ -4114,7 +4114,7 @@ description:
Check that exec exits for built-ins Check that exec exits for built-ins
arguments: !-i! arguments: !-i!
stdin: stdin:
exec print hi exec echo hi
echo still herre echo still herre
expected-stdout: expected-stdout:
hi hi
@ -4364,7 +4364,7 @@ description:
stdin: stdin:
test \( -f = -f \) test \( -f = -f \)
rv=$? rv=$?
set -o posix set -o sh
echo -e $rv echo -e $rv
expected-stdout: expected-stdout:
-e 0 -e 0
@ -4458,44 +4458,44 @@ stdin:
expected-stdout: expected-stdout:
x x
--- ---
name: posix-mode-1 name: sh-mode-1
description: description:
Check that posix mode turns braceexpand off Check that sh mode turns braceexpand off
and that that works correctly and that that works correctly
stdin: stdin:
set -o braceexpand set -o braceexpand
set +o posix set +o sh
[[ $(set +o) == *@(-o posix)@(| *) ]] && echo posix || echo noposix [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
[[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
echo {a,b,c} echo {a,b,c}
set +o braceexpand set +o braceexpand
echo {a,b,c} echo {a,b,c}
set -o braceexpand set -o braceexpand
echo {a,b,c} echo {a,b,c}
set -o posix set -o sh
echo {a,b,c} echo {a,b,c}
[[ $(set +o) == *@(-o posix)@(| *) ]] && echo posix || echo noposix [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
[[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
set -o braceexpand set -o braceexpand
echo {a,b,c} echo {a,b,c}
[[ $(set +o) == *@(-o posix)@(| *) ]] && echo posix || echo noposix [[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh
[[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex [[ $(set +o) == *@(-o braceexpand)@(| *) ]] && echo brex || echo nobrex
expected-stdout: expected-stdout:
noposix nosh
brex brex
a b c a b c
{a,b,c} {a,b,c}
a b c a b c
{a,b,c} {a,b,c}
posix sh
nobrex nobrex
a b c a b c
posix sh
brex brex
--- ---
name: posix-mode-2a name: sh-mode-2a
description: description:
Check that posix mode is *not* automatically turned on Check that sh mode is *not* automatically turned on
category: !binsh category: !binsh
stdin: stdin:
ln -s "$__progname" ksh ln -s "$__progname" ksh
@ -4504,17 +4504,17 @@ stdin:
ln -s "$__progname" ./-sh ln -s "$__progname" ./-sh
for shell in {,-}{,k}sh; do for shell in {,-}{,k}sh; do
print -- $shell $(./$shell +l -c \ print -- $shell $(./$shell +l -c \
'[[ $(set +o) == *@(-o posix)@(| *) ]] && echo posix || echo noposix') '[[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh')
done done
expected-stdout: expected-stdout:
sh noposix sh nosh
ksh noposix ksh nosh
-sh noposix -sh nosh
-ksh noposix -ksh nosh
--- ---
name: posix-mode-2b name: sh-mode-2b
description: description:
Check that posix mode is automatically turned on Check that sh mode *is* automatically turned on
category: binsh category: binsh
stdin: stdin:
ln -s "$__progname" ksh ln -s "$__progname" ksh
@ -4523,13 +4523,13 @@ stdin:
ln -s "$__progname" ./-sh ln -s "$__progname" ./-sh
for shell in {,-}{,k}sh; do for shell in {,-}{,k}sh; do
print -- $shell $(./$shell +l -c \ print -- $shell $(./$shell +l -c \
'[[ $(set +o) == *@(-o posix)@(| *) ]] && echo posix || echo noposix') '[[ $(set +o) == *@(-o sh)@(| *) ]] && echo sh || echo nosh')
done done
expected-stdout: expected-stdout:
sh posix sh sh
ksh noposix ksh nosh
-sh posix -sh sh
-ksh noposix -ksh nosh
--- ---
name: pipeline-1 name: pipeline-1
description: description:
@ -4561,9 +4561,9 @@ name: pipeline-2
description: description:
check that co-processes work with TCOMs, TPIPEs and TPARENs check that co-processes work with TCOMs, TPIPEs and TPARENs
stdin: stdin:
"$__progname" -c 'i=100; print hi |& while read -p line; do print "$((i++)) $line"; done' "$__progname" -c 'i=100; echo hi |& while read -p line; do echo "$((i++)) $line"; done'
"$__progname" -c 'i=200; print hi | cat |& while read -p line; do print "$((i++)) $line"; done' "$__progname" -c 'i=200; echo hi | cat |& while read -p line; do echo "$((i++)) $line"; done'
"$__progname" -c 'i=300; (print hi | cat) |& while read -p line; do print "$((i++)) $line"; done' "$__progname" -c 'i=300; (echo hi | cat) |& while read -p line; do echo "$((i++)) $line"; done'
expected-stdout: expected-stdout:
100 hi 100 hi
200 hi 200 hi
@ -4593,7 +4593,7 @@ stdin:
typeset -ZL10 lz=0hall0 typeset -ZL10 lz=0hall0
typeset -ZR10 rz=0hall0 typeset -ZR10 rz=0hall0
typeset -Z10 rx=" hallo " typeset -Z10 rx=" hallo "
print "<$ln> <$rn> <$lz> <$rz> <$rx>" echo "<$ln> <$rn> <$lz> <$rz> <$rx>"
expected-stdout: expected-stdout:
<0hall0 > < 0hall0> <hall0 > <00000hall0> <0000 hallo> <0hall0 > < 0hall0> <hall0 > <00000hall0> <0000 hallo>
--- ---
@ -4607,7 +4607,7 @@ stdin:
typeset -L9 ls=16#1 typeset -L9 ls=16#1
typeset -R9 rs=16#1 typeset -R9 rs=16#1
typeset -Z9 zs=16#1 typeset -Z9 zs=16#1
print "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>" echo "<$ln> <$rn> <$zn> <$ls> <$rs> <$zs>"
expected-stdout: expected-stdout:
<16#1 > < 16#1> <16#000001> <16#1 > < 16#1> <0000016#1> <16#1 > < 16#1> <16#000001> <16#1 > < 16#1> <0000016#1>
--- ---
@ -4625,7 +4625,7 @@ stdin:
print 'fnord\nfnord\nfnord\nfnord' >foo/bar print 'fnord\nfnord\nfnord\nfnord' >foo/bar
print eval \''fnord\nfnord\»¿fnord\nfnord'\' >foo/zoo print eval \''fnord\nfnord\»¿fnord\nfnord'\' >foo/zoo
set -A anzahl -- foo/* set -A anzahl -- foo/*
print got ${#anzahl[*]} files echo got ${#anzahl[*]} files
chmod +x foo/* chmod +x foo/*
export PATH=$(pwd)/foo:$PATH export PATH=$(pwd)/foo:$PATH
"$__progname" -c 'fnord' "$__progname" -c 'fnord'
@ -4638,7 +4638,7 @@ stdin:
echo = echo =
"$__progname" foo/zoo "$__progname" foo/zoo
echo = echo =
"$__progname" -c 'print : $(fnord)' "$__progname" -c 'echo : $(fnord)'
rm -rf foo rm -rf foo
expected-stdout: expected-stdout:
got 4 files got 4 files
@ -4696,8 +4696,8 @@ name: utf8bom-3
description: description:
Reading the UTF-8 BOM should enable the utf8-mode flag Reading the UTF-8 BOM should enable the utf8-mode flag
stdin: stdin:
"$__progname" -c ':; if [[ $- = *U* ]]; then print 1 on; else print 1 off; fi' "$__progname" -c ':; if [[ $- = *U* ]]; then echo 1 on; else echo 1 off; fi'
"$__progname" -c ':; if [[ $- = *U* ]]; then print 2 on; else print 2 off; fi' "$__progname" -c ':; if [[ $- = *U* ]]; then echo 2 on; else echo 2 off; fi'
expected-stdout: expected-stdout:
1 off 1 off
2 on 2 on
@ -4709,9 +4709,9 @@ category: !os:hpux
env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8! env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
stdin: stdin:
if [[ $- = *U* ]]; then if [[ $- = *U* ]]; then
print is set echo is set
else else
print is not set echo is not set
fi fi
expected-stdout: expected-stdout:
is not set is not set
@ -4723,9 +4723,9 @@ category: os:hpux
env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8! env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
stdin: stdin:
if [[ $- = *U* ]]; then if [[ $- = *U* ]]; then
print is set echo is set
else else
print is not set echo is not set
fi fi
expected-stdout: expected-stdout:
is not set is not set
@ -4742,9 +4742,9 @@ arguments: !-i!
env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8! env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
stdin: stdin:
if [[ $- = *U* ]]; then if [[ $- = *U* ]]; then
print is set echo is set
else else
print is not set echo is not set
fi fi
expected-stdout: expected-stdout:
is set is set
@ -4760,9 +4760,9 @@ arguments: !-i!
env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8! env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
stdin: stdin:
if [[ $- = *U* ]]; then if [[ $- = *U* ]]; then
print is set echo is set
else else
print is not set echo is not set
fi fi
expected-stdout: expected-stdout:
is set is set
@ -4815,9 +4815,9 @@ expected-stdout:
--- ---
name: aliases-2a name: aliases-2a
description: description:
Check if set -o posix disables built-in aliases (except a few) Check if set -o sh disables built-in aliases (except a few)
category: disabled category: disabled
arguments: !-o!posix! arguments: !-o!sh!
stdin: stdin:
alias alias
typeset -f typeset -f
@ -4829,7 +4829,7 @@ name: aliases-3a
description: description:
Check if running as sh disables built-in aliases (except a few) Check if running as sh disables built-in aliases (except a few)
category: disabled category: disabled
arguments: !-o!posix! arguments: !-o!sh!
stdin: stdin:
cp "$__progname" sh cp "$__progname" sh
./sh -c 'alias; typeset -f' ./sh -c 'alias; typeset -f'
@ -4840,9 +4840,9 @@ expected-stdout:
--- ---
name: aliases-2b name: aliases-2b
description: description:
Check if set -o posix does not influence built-in aliases Check if set -o sh does not influence built-in aliases
category: !arge category: !arge
arguments: !-o!posix! arguments: !-o!sh!
stdin: stdin:
alias alias
typeset -f typeset -f
@ -4866,7 +4866,7 @@ name: aliases-3b
description: description:
Check if running as sh does not influence built-in aliases Check if running as sh does not influence built-in aliases
category: !arge category: !arge
arguments: !-o!posix! arguments: !-o!sh!
stdin: stdin:
cp "$__progname" sh cp "$__progname" sh
./sh -c 'alias; typeset -f' ./sh -c 'alias; typeset -f'
@ -4889,9 +4889,9 @@ expected-stdout:
--- ---
name: aliases-2b-hartz4 name: aliases-2b-hartz4
description: description:
Check if set -o posix does not influence built-in aliases Check if set -o sh does not influence built-in aliases
category: arge category: arge
arguments: !-o!posix! arguments: !-o!sh!
stdin: stdin:
alias alias
typeset -f typeset -f
@ -4913,7 +4913,7 @@ name: aliases-3b-hartz4
description: description:
Check if running as sh does not influence built-in aliases Check if running as sh does not influence built-in aliases
category: arge category: arge
arguments: !-o!posix! arguments: !-o!sh!
stdin: stdin:
cp "$__progname" sh cp "$__progname" sh
./sh -c 'alias; typeset -f' ./sh -c 'alias; typeset -f'
@ -4996,9 +4996,9 @@ stdin:
set -A foo a b c set -A foo a b c
foo[4097]=d foo[4097]=d
foo[2147483637]=e foo[2147483637]=e
print ${foo[*]} echo ${foo[*]}
foo[-1]=f foo[-1]=f
print ${foo[4294967295]} g ${foo[*]} echo ${foo[4294967295]} g ${foo[*]}
expected-stdout: expected-stdout:
a b c d e a b c d e
f g a b c d e f f g a b c d e f
@ -5073,17 +5073,17 @@ description:
Check if we can get the array keys (indices) for indexed arrays, Check if we can get the array keys (indices) for indexed arrays,
Korn shell style, in some corner cases Korn shell style, in some corner cases
stdin: stdin:
print !arz: ${!arz} echo !arz: ${!arz}
print !arz[0]: ${!arz[0]} echo !arz[0]: ${!arz[0]}
print !arz[1]: ${!arz[1]} echo !arz[1]: ${!arz[1]}
arz=foo arz=foo
print !arz: ${!arz} echo !arz: ${!arz}
print !arz[0]: ${!arz[0]} echo !arz[0]: ${!arz[0]}
print !arz[1]: ${!arz[1]} echo !arz[1]: ${!arz[1]}
unset arz unset arz
print !arz: ${!arz} echo !arz: ${!arz}
print !arz[0]: ${!arz[0]} echo !arz[0]: ${!arz[0]}
print !arz[1]: ${!arz[1]} echo !arz[1]: ${!arz[1]}
expected-stdout: expected-stdout:
!arz: 0 !arz: 0
!arz[0]: !arz[0]:
@ -5103,13 +5103,13 @@ stdin:
x=abcdefghi x=abcdefghi
typeset -i y=123456789 typeset -i y=123456789
typeset -i 16 z=123456789 # 16#75bcd15 typeset -i 16 z=123456789 # 16#75bcd15
print a t${x:2:2} ${y:2:3} ${z:2:3} a echo a t${x:2:2} ${y:2:3} ${z:2:3} a
print b ${x::3} ${y::3} ${z::3} b echo b ${x::3} ${y::3} ${z::3} b
print c ${x:2:} ${y:2:} ${z:2:} c echo c ${x:2:} ${y:2:} ${z:2:} c
print d ${x:2} ${y:2} ${z:2} d echo d ${x:2} ${y:2} ${z:2} d
print e ${x:2:6} ${y:2:6} ${z:2:7} e echo e ${x:2:6} ${y:2:6} ${z:2:7} e
print f ${x:2:7} ${y:2:7} ${z:2:8} f echo f ${x:2:7} ${y:2:7} ${z:2:8} f
print g ${x:2:8} ${y:2:8} ${z:2:9} g echo g ${x:2:8} ${y:2:8} ${z:2:9} g
expected-stdout: expected-stdout:
a tcd 345 #75 a a tcd 345 #75 a
b abc 123 16# b b abc 123 16# b
@ -5128,10 +5128,10 @@ stdin:
typeset -i y=123456789 typeset -i y=123456789
typeset -i 16 z=123456789 # 16#75bcd15 typeset -i 16 z=123456789 # 16#75bcd15
n=2 n=2
print a ${x:$n:3} ${y:$n:3} ${z:$n:3} a echo a ${x:$n:3} ${y:$n:3} ${z:$n:3} a
print b ${x:(n):3} ${y:(n):3} ${z:(n):3} b echo b ${x:(n):3} ${y:(n):3} ${z:(n):3} b
print c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c echo c ${x:(-2):1} ${y:(-2):1} ${z:(-2):1} c
print d t${x: n:2} ${y: n:3} ${z: n:3} d echo d t${x: n:2} ${y: n:3} ${z: n:3} d
expected-stdout: expected-stdout:
a cde 345 #75 a a cde 345 #75 a
b cde 345 #75 b b cde 345 #75 b
@ -5164,7 +5164,7 @@ description:
stdin: stdin:
x=abcdefghi x=abcdefghi
integer y=2 integer y=2
print a ${x:(y == 1 ? 2 : 3):4} a echo a ${x:(y == 1 ? 2 : 3):4} a
expected-stdout: expected-stdout:
a defg a a defg a
--- ---
@ -5174,10 +5174,10 @@ description:
stdin: stdin:
set +U set +U
x=¤h x=¤h
print a ${x::1} ${x: -1} a echo a ${x::1} ${x: -1} a
print b ${x::3} ${x: -3} b echo b ${x::3} ${x: -3} b
print c ${x:1:2} ${x: -3:2} c echo c ${x:1:2} ${x: -3:2} c
print d ${#x} d echo d ${#x} d
expected-stdout: expected-stdout:
a m h a a m h a
b ¤ äh b b ¤ äh b
@ -5190,10 +5190,10 @@ description:
stdin: stdin:
set -U set -U
x=¤h x=¤h
print a ${x::1} ${x: -1} a echo a ${x::1} ${x: -1} a
print b ${x::2} ${x: -2} b echo b ${x::2} ${x: -2} b
print c ${x:1:1} ${x: -2:1} c echo c ${x:1:1} ${x: -2:1} c
print d ${#x} d echo d ${#x} d
expected-stdout: expected-stdout:
a m h a a m h a
b ¤ äh b b ¤ äh b
@ -5427,16 +5427,16 @@ stdin:
typeset -Uui1 o0b=0x7E typeset -Uui1 o0b=0x7E
typeset -Uui1 o1b=0xFDD0 typeset -Uui1 o1b=0xFDD0
integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f integer px=0xCAFE 'p0=1# ' p1=1#… pl=1#f
print "in <$i0> <$i1>" echo "in <$i0> <$i1>"
print "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>" echo "out <${o0a#1#}|${o0b#1#}> <${o1a#1#}|${o1b#1#}>"
typeset -Uui1 i0 i1 typeset -Uui1 i0 i1
print "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>" echo "pass <$px> <$p0> <$p1> <$pl> <${i0#1#}|${i1#1#}>"
typeset -Uui16 tv1=1#~ tv2=1# tv3=1#€ tv4=1#<23> tv5=1#À tv6=1#Á tv7=1#  tv8=1#€ typeset -Uui16 tv1=1#~ tv2=1# tv3=1#€ tv4=1#<23> tv5=1#À tv6=1#Á tv7=1#  tv8=1#€
print "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>" echo "specX <${tv1#16#}> <${tv2#16#}> <${tv3#16#}> <${tv4#16#}> <${tv5#16#}> <${tv6#16#}> <${tv7#16#}> <${tv8#16#}>"
typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8 typeset -i1 tv1 tv2 tv3 tv4 tv5 tv6 tv7 tv8
print "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>" echo "specW <${tv1#1#}> <${tv2#1#}> <${tv3#1#}> <${tv4#1#}> <${tv5#1#}> <${tv6#1#}> <${tv7#1#}> <${tv8#1#}>"
typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0 typeset -i1 xs1=0xEF7F xs2=0xEF80 xs3=0xFDD0
print "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>" echo "specU <${xs1#1#}> <${xs2#1#}> <${xs3#1#}>"
expected-stdout: expected-stdout:
in <16#EFEF> <16#20AC> in <16#EFEF> <16#20AC>
out <@|~> <☺|ï·<C3AF>> out <@|~> <☺|ï·<C3AF>>
@ -5451,7 +5451,7 @@ description:
stdin: stdin:
set -U set -U
integer x=1#foo integer x=1#foo
print /$x/ echo /$x/
expected-stderr-pattern: expected-stderr-pattern:
/1#foo: unexpected 'oo'/ /1#foo: unexpected 'oo'/
expected-exit: e != 0 expected-exit: e != 0
@ -5462,7 +5462,7 @@ description:
stdin: stdin:
set -U set -U
integer x=1#À€ integer x=1#À€
print /$x/ echo /$x/
expected-stderr-pattern: expected-stderr-pattern:
/1#À€: unexpected '€'/ /1#À€: unexpected '€'/
expected-exit: e != 0 expected-exit: e != 0
@ -5473,7 +5473,7 @@ description:
stdin: stdin:
set -U set -U
integer x=1#… integer x=1#…
print /$x/ echo /$x/
expected-stdout: expected-stdout:
/1#…/ /1#…/
--- ---
@ -5483,7 +5483,7 @@ description:
stdin: stdin:
set +U set +U
integer x=1#… integer x=1#…
print /$x/ echo /$x/
expected-stderr-pattern: expected-stderr-pattern:
/1#…: unexpected '€'/ /1#…: unexpected '€'/
expected-exit: e != 0 expected-exit: e != 0
@ -5494,7 +5494,7 @@ description:
stdin: stdin:
set -U set -U
typeset -i16 x=1#ÿ typeset -i16 x=1#ÿ
print /$x/ # invalid utf-8 echo /$x/ # invalid utf-8
expected-stdout: expected-stdout:
/16#efff/ /16#efff/
--- ---
@ -5504,7 +5504,7 @@ description:
stdin: stdin:
set -U set -U
typeset -i16 x=1 typeset -i16 x=1
print /$x/ # invalid 2-byte echo /$x/ # invalid 2-byte
expected-stdout: expected-stdout:
/16#efc2/ /16#efc2/
--- ---
@ -5514,7 +5514,7 @@ description:
stdin: stdin:
set -U set -U
typeset -i16 x=1 typeset -i16 x=1
print /$x/ # invalid 2-byte echo /$x/ # invalid 2-byte
expected-stdout: expected-stdout:
/16#efef/ /16#efef/
--- ---
@ -5524,7 +5524,7 @@ description:
stdin: stdin:
set -U set -U
typeset -i16 x=1#ï¿À typeset -i16 x=1#ï¿À
print /$x/ # invalid 3-byte echo /$x/ # invalid 3-byte
expected-stderr-pattern: expected-stderr-pattern:
/1#ï¿À: unexpected '¿'/ /1#ï¿À: unexpected '¿'/
expected-exit: e != 0 expected-exit: e != 0
@ -5535,7 +5535,7 @@ description:
stdin: stdin:
set -U set -U
typeset -i16 x=1#À€ typeset -i16 x=1#À€
print /$x/ # non-minimalistic echo /$x/ # non-minimalistic
expected-stderr-pattern: expected-stderr-pattern:
/1#À€: unexpected '€'/ /1#À€: unexpected '€'/
expected-exit: e != 0 expected-exit: e != 0
@ -5546,7 +5546,7 @@ description:
stdin: stdin:
set -U set -U
typeset -i16 x=1#à€€ typeset -i16 x=1#à€€
print /$x/ # non-minimalistic echo /$x/ # non-minimalistic
expected-stderr-pattern: expected-stderr-pattern:
/1#à€€: unexpected '€'/ /1#à€€: unexpected '€'/
expected-exit: e != 0 expected-exit: e != 0
@ -5727,13 +5727,13 @@ description:
category: !smksh category: !smksh
stdin: stdin:
set -U set -U
print 1 $(('a')) echo 1 $(('a'))
(print 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/" (echo 2f $(('aa'))) 2>&1 | sed "s/^[^']*'/2p '/"
print 3 $(('…')) echo 3 $(('…'))
x="'a'" x="'a'"
print "4 <$x>" echo "4 <$x>"
print 5 $(($x)) echo 5 $(($x))
print 6 $((x)) echo 6 $((x))
expected-stdout: expected-stdout:
1 97 1 97
2p 'aa': multi-character character constant 2p 'aa': multi-character character constant
@ -5747,9 +5747,9 @@ description:
Check if we can use a specific syntax idiom for ulimit Check if we can use a specific syntax idiom for ulimit
stdin: stdin:
if ! x=$(ulimit -d); then if ! x=$(ulimit -d); then
print expected to fail on this OS echo expected to fail on this OS
else else
ulimit -dS $x && print okay ulimit -dS $x && echo okay
fi fi
expected-stdout: expected-stdout:
okay okay
@ -5912,7 +5912,7 @@ description:
category: !convfds category: !convfds
stdin: stdin:
read -u10 foo 10<<< bar read -u10 foo 10<<< bar
print x$foo echo x$foo
expected-stdout: expected-stdout:
xbar xbar
--- ---
@ -5923,7 +5923,7 @@ category: !convfds
stdin: stdin:
exec 12>foo exec 12>foo
print -u12 bar print -u12 bar
print baz >&12 echo baz >&12
cat foo cat foo
expected-stdout: expected-stdout:
bar bar
@ -5955,7 +5955,7 @@ description:
Calling Calling
FOO=bar f FOO=bar f
where f is a ksh style function, should not set FOO in the current where f is a ksh style function, should not set FOO in the current
env. If f is a bourne style function, FOO should be set. Furthermore, env. If f is a Bourne style function, FOO should be set. Furthermore,
the function should receive a correct value of FOO. Additionally, the function should receive a correct value of FOO. Additionally,
setting FOO in the function itself should not change the value in setting FOO in the function itself should not change the value in
global environment. global environment.
@ -6036,7 +6036,7 @@ description:
file-setup: file 644 "test.sh" file-setup: file 644 "test.sh"
print -u3 Fowl print -u3 Fowl
stdin: stdin:
set -o posix set -o sh
exec 3>&1 exec 3>&1
"$__progname" test.sh "$__progname" test.sh
expected-stdout: expected-stdout:
@ -6285,7 +6285,7 @@ expected-stdout:
--- ---
name: nounset-1 name: nounset-1
description: description:
Check that "set -u" matches (future) POSIX requirement Check that "set -u" matches (future) SUSv4 requirement
stdin: stdin:
(set -u (set -u
try() { try() {
@ -6366,25 +6366,25 @@ stdin:
bar=global bar=global
typeset -n ir2=bar typeset -n ir2=bar
typeset -n ind=ir2 typeset -n ind=ir2
print !ind: ${!ind} echo !ind: ${!ind}
print ind: $ind echo ind: $ind
print !ir2: ${!ir2} echo !ir2: ${!ir2}
print ir2: $ir2 echo ir2: $ir2
typeset +n ind typeset +n ind
print !ind: ${!ind} echo !ind: ${!ind}
print ind: $ind echo ind: $ind
typeset -n ir2=ind typeset -n ir2=ind
print !ir2: ${!ir2} echo !ir2: ${!ir2}
print ir2: $ir2 echo ir2: $ir2
set|grep ^ir2|sed 's/^/s1: /' set|grep ^ir2|sed 's/^/s1: /'
typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/' typeset|grep ' ir2'|sed -e 's/^/s2: /' -e 's/nameref/typeset -n/'
set -A blub -- e1 e2 e3 set -A blub -- e1 e2 e3
typeset -n ind=blub typeset -n ind=blub
typeset -n ir2=blub[2] typeset -n ir2=blub[2]
print !ind[1]: ${!ind[1]} echo !ind[1]: ${!ind[1]}
print !ir2: $!ir2 echo !ir2: $!ir2
print ind[1]: ${ind[1]} echo ind[1]: ${ind[1]}
print ir2: $ir2 echo ir2: $ir2
expected-stdout: expected-stdout:
!ind: bar !ind: bar
ind: global ind: global
@ -6409,21 +6409,21 @@ stdin:
function foo { function foo {
typeset bar=lokal baz=auch typeset bar=lokal baz=auch
typeset -n v=bar typeset -n v=bar
print entering echo entering
print !v: ${!v} echo !v: ${!v}
print !bar: ${!bar} echo !bar: ${!bar}
print !baz: ${!baz} echo !baz: ${!baz}
print bar: $bar echo bar: $bar
print v: $v echo v: $v
v=123 v=123
print bar: $bar echo bar: $bar
print v: $v echo v: $v
print exiting echo exiting
} }
bar=global bar=global
print bar: $bar echo bar: $bar
foo bar foo bar
print bar: $bar echo bar: $bar
expected-stdout: expected-stdout:
bar: global bar: global
entering entering

8
exec.c
View File

@ -22,7 +22,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.65 2009/09/20 16:40:55 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.66 2009/10/02 18:08:32 tg Exp $");
static int comexec(struct op *, struct tbl *volatile, const char **, static int comexec(struct op *, struct tbl *volatile, const char **,
int volatile, volatile int *); int volatile, volatile int *);
@ -408,7 +408,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap,
int type_flags; int type_flags;
int keepasn_ok; int keepasn_ok;
int fcflags = FC_BI|FC_FUNC|FC_PATH; int fcflags = FC_BI|FC_FUNC|FC_PATH;
int bourne_function_call = 0; bool bourne_function_call = false;
/* snag the last argument for $_ XXX not the same as AT&T ksh, /* snag the last argument for $_ XXX not the same as AT&T ksh,
* which only seems to set $_ after a newline (but not in * which only seems to set $_ after a newline (but not in
@ -496,7 +496,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap,
/* ksh functions don't keep assignments, POSIX functions do. */ /* ksh functions don't keep assignments, POSIX functions do. */
if (keepasn_ok && tp && tp->type == CFUNC && if (keepasn_ok && tp && tp->type == CFUNC &&
!(tp->flag & FKSH)) { !(tp->flag & FKSH)) {
bourne_function_call = 1; bourne_function_call = true;
type_flags = 0; type_flags = 0;
} else } else
type_flags = LOCAL|LOCAL_COPY|EXPORT; type_flags = LOCAL|LOCAL_COPY|EXPORT;
@ -591,7 +591,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap,
; ;
e->loc->argc = i - 1; e->loc->argc = i - 1;
/* ksh-style functions handle getopts sanely, /* ksh-style functions handle getopts sanely,
* bourne/posix functions are insane... * Bourne/POSIX functions are insane...
*/ */
if (tp->flag & FKSH) { if (tp->flag & FKSH) {
e->loc->flags |= BF_DOGETOPTS; e->loc->flags |= BF_DOGETOPTS;

View File

@ -25,7 +25,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.135 2009/09/26 03:39:58 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.136 2009/10/02 18:08:33 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@ -526,7 +526,7 @@ c_print(const char **wp)
* by default. * by default.
*/ */
wp += 1; wp += 1;
if (Flag(FPOSIX)) { if (Flag(FSH)) {
if (*wp && strcmp(*wp, "-n") == 0) { if (*wp && strcmp(*wp, "-n") == 0) {
flags &= ~PO_NL; flags &= ~PO_NL;
wp++; wp++;
@ -2410,7 +2410,7 @@ timex(struct op *t, int f, volatile int *xerrok)
{ {
#define TF_NOARGS BIT(0) #define TF_NOARGS BIT(0)
#define TF_NOREAL BIT(1) /* don't report real time */ #define TF_NOREAL BIT(1) /* don't report real time */
#define TF_POSIX BIT(2) /* report in posix format */ #define TF_POSIX BIT(2) /* report in POSIX format */
int rv = 0, tf = 0; int rv = 0, tf = 0;
struct rusage ru0, ru1, cru0, cru1; struct rusage ru0, ru1, cru0, cru1;
struct timeval usrtime, systime, tv0, tv1; struct timeval usrtime, systime, tv0, tv1;
@ -2519,7 +2519,7 @@ c_exec(const char **wp __unused)
if (e->savefd[i] > 0) if (e->savefd[i] > 0)
close(e->savefd[i]); close(e->savefd[i]);
/* For ksh (but not sh), keep anything > 2 private */ /* For ksh (but not sh), keep anything > 2 private */
if (!Flag(FPOSIX) && i > 2 && e->savefd[i]) if (!Flag(FSH) && i > 2 && e->savefd[i])
fcntl(i, F_SETFD, FD_CLOEXEC); fcntl(i, F_SETFD, FD_CLOEXEC);
} }
e->savefd = NULL; e->savefd = NULL;

View File

@ -26,7 +26,7 @@
#include <sys/file.h> #include <sys/file.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.88 2009/08/08 13:08:51 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.89 2009/10/02 18:08:33 tg Exp $");
/*- /*-
* MirOS: This is the default mapping type, and need not be specified. * MirOS: This is the default mapping type, and need not be specified.
@ -108,7 +108,7 @@ c_fc(const char **wp)
case 'r': case 'r':
rflag++; rflag++;
break; break;
case 's': /* posix version of -e - */ case 's': /* POSIX version of -e - */
sflag++; sflag++;
break; break;
/* kludge city - accept -num as -- -num (kind of) */ /* kludge city - accept -num as -- -num (kind of) */
@ -311,7 +311,7 @@ hist_execute(char *cmd)
} }
/* Commands are executed here instead of pushing them onto the /* Commands are executed here instead of pushing them onto the
* input 'cause posix says the redirection and variable assignments * input 'cause POSIX says the redirection and variable assignments
* in * in
* X=y fc -e - 42 2> /dev/null * X=y fc -e - 42 2> /dev/null
* are to effect the repeated commands environment. * are to effect the repeated commands environment.

4
lex.c
View File

@ -22,7 +22,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.97 2009/09/24 17:15:31 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/lex.c,v 1.98 2009/10/02 18:08:34 tg Exp $");
/* /*
* states while lexing word * states while lexing word
@ -477,7 +477,7 @@ yylex(int cf)
/* Need to know if we are inside double quotes /* Need to know if we are inside double quotes
* since sh/AT&T-ksh translate the \" to " in * since sh/AT&T-ksh translate the \" to " in
* "`..\"..`". * "`..\"..`".
* This is not done in posix mode (section * This is not done in POSIX mode (section
* 3.2.3, Double Quotes: "The backquote shall * 3.2.3, Double Quotes: "The backquote shall
* retain its special meaning introducing the * retain its special meaning introducing the
* other form of command substitution (see * other form of command substitution (see

12
main.c
View File

@ -33,7 +33,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.151 2009/09/29 12:28:13 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.152 2009/10/02 18:08:34 tg Exp $");
extern char **environ; extern char **environ;
@ -210,7 +210,7 @@ main(int argc, const char *argv[])
#endif #endif
#ifdef MKSH_BINSHREDUCED #ifdef MKSH_BINSHREDUCED
/* set FPOSIX if we're called as -sh or /bin/sh or so */ /* set FSH if we're called as -sh or /bin/sh or so */
{ {
const char *cc; const char *cc;
@ -221,7 +221,7 @@ main(int argc, const char *argv[])
if ((cc[i++] | 2) == '/') if ((cc[i++] | 2) == '/')
argi = i; argi = i;
if (((cc[argi] | 0x20) == 's') && ((cc[argi + 1] | 0x20) == 'h')) if (((cc[argi] | 0x20) == 's') && ((cc[argi + 1] | 0x20) == 'h'))
change_flag(FPOSIX, OF_FIRSTTIME, 1); change_flag(FSH, OF_FIRSTTIME, 1);
} }
#endif #endif
@ -313,7 +313,7 @@ main(int argc, const char *argv[])
errorf("-c requires an argument"); errorf("-c requires an argument");
#ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT #ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT
/* compatibility to MidnightBSD 0.1 /bin/sh (not desired) */ /* compatibility to MidnightBSD 0.1 /bin/sh (not desired) */
if (Flag(FPOSIX) && argv[argi] && !strcmp(argv[argi], "--")) if (Flag(FSH) && argv[argi] && !strcmp(argv[argi], "--"))
++argi; ++argi;
#endif #endif
if (argv[argi]) if (argv[argi])
@ -346,7 +346,7 @@ main(int argc, const char *argv[])
} }
} }
/* This bizarreness is mandated by POSIX */ /* this bizarreness is mandated by POSIX */
if (fstat(0, &s_stdin) >= 0 && S_ISCHR(s_stdin.st_mode) && if (fstat(0, &s_stdin) >= 0 && S_ISCHR(s_stdin.st_mode) &&
Flag(FTALKING)) Flag(FTALKING))
reset_nonblock(0); reset_nonblock(0);
@ -1113,7 +1113,7 @@ check_fd(const char *name, int mode, const char **emsgp)
fl &= O_ACCMODE; fl &= O_ACCMODE;
/* X_OK is a kludge to disable this check for dups (x<&1): /* X_OK is a kludge to disable this check for dups (x<&1):
* historical shells never did this check (XXX don't know what * historical shells never did this check (XXX don't know what
* posix has to say). * POSIX has to say).
*/ */
if (!(mode & X_OK) && fl != O_RDWR && ( if (!(mode & X_OK) && fl != O_RDWR && (
((mode & R_OK) && fl != O_RDONLY) || ((mode & R_OK) && fl != O_RDONLY) ||

4
misc.c
View File

@ -29,7 +29,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.124 2009/09/24 17:15:32 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.125 2009/10/02 18:08:35 tg Exp $");
#undef USE_CHVT #undef USE_CHVT
/* XXX conditions correct? */ /* XXX conditions correct? */
@ -226,7 +226,7 @@ change_flag(enum sh_flag f, int what, unsigned int newval)
setegid(kshegid = kshgid = getgid()); setegid(kshegid = kshgid = getgid());
setgid(kshegid); setgid(kshegid);
#endif #endif
} else if (f == FPOSIX && newval) { } else if (f == FSH && newval) {
Flag(FBRACEEXPAND) = 0; Flag(FBRACEEXPAND) = 0;
} }
/* Changing interactive flag? */ /* Changing interactive flag? */

15
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.192 2009/09/26 03:40:00 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.193 2009/10/02 18:08:35 tg Exp $
.\" $OpenBSD: ksh.1,v 1.129 2009/05/28 06:09:06 jmc Exp $ .\" $OpenBSD: ksh.1,v 1.129 2009/05/28 06:09:06 jmc Exp $
.\"- .\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
@ -48,7 +48,7 @@
.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 .el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
.. ..
.\"- .\"-
.Dd $Mdocdate: September 26 2009 $ .Dd $Mdocdate: October 2 2009 $
.Dt MKSH 1 .Dt MKSH 1
.Os MirBSD .Os MirBSD
.Sh NAME .Sh NAME
@ -2234,7 +2234,7 @@ will print an error with a line number prepended to it:
.Pp .Pp
File descriptors created by input/output redirections are private to the File descriptors created by input/output redirections are private to the
Korn shell, but passed to sub-processes if Korn shell, but passed to sub-processes if
.Fl o Ic posix .Fl o Ic sh
is set. is set.
.Ss Arithmetic expressions .Ss Arithmetic expressions
Integer arithmetic expressions can be used with the Integer arithmetic expressions can be used with the
@ -3030,7 +3030,7 @@ enables backslash interpretation (a no-op, since this is normally done), and
suppresses backslash interpretation. suppresses backslash interpretation.
.Pp .Pp
If the If the
.Ic posix .Ic sh
option is set, only the first argument is treated as an option, and only option is set, only the first argument is treated as an option, and only
if it is exactly if it is exactly
.Dq Fl n . .Dq Fl n .
@ -3802,8 +3802,11 @@ See the
and and
.Ic pwd .Ic pwd
commands above for more details. commands above for more details.
.It Ic posix .It Ic sh
Enable POSIX mode. Enable
.Pa /bin/sh
.Pq POSIX/kludge
mode.
Automatically enabled if the basename of the shell invocation begins with Automatically enabled if the basename of the shell invocation begins with
.Dq sh .Dq sh
and this autodetection feature was requested at compilation time. and this autodetection feature was requested at compilation time.

4
sh.h
View File

@ -134,9 +134,9 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.351 2009/09/29 12:28:13 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.352 2009/10/02 18:08:36 tg Exp $");
#endif #endif
#define MKSH_VERSION "R39 2009/09/29" #define MKSH_VERSION "R39 2009/10/02"
#ifndef MKSH_INCLUDES_ONLY #ifndef MKSH_INCLUDES_ONLY

View File

@ -1,5 +1,5 @@
#if defined(SHFLAGS_DEFNS) #if defined(SHFLAGS_DEFNS)
__RCSID("$MirOS: src/bin/mksh/sh_flags.h,v 1.3 2009/09/26 03:40:02 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh_flags.h,v 1.4 2009/10/02 18:08:37 tg Exp $");
#define FN(sname,cname,ochar,flags) /* nothing */ #define FN(sname,cname,ochar,flags) /* nothing */
#elif defined(SHFLAGS_ENUMS) #elif defined(SHFLAGS_ENUMS)
#define FN(sname,cname,ochar,flags) cname, #define FN(sname,cname,ochar,flags) cname,
@ -89,15 +89,15 @@ FN("nounset", FNOUNSET, 'u', OF_ANY)
/* ./. don't do logical cds/pwds (non-standard) */ /* ./. don't do logical cds/pwds (non-standard) */
FN("physical", FPHYSICAL, 0, OF_ANY) FN("physical", FPHYSICAL, 0, OF_ANY)
/* ./. mock POSIX mode (try to be more compatible; non-standard) */
FN("posix", FPOSIX, 0, OF_ANY)
/* -p use suid_profile; privileged shell */ /* -p use suid_profile; privileged shell */
FN("privileged", FPRIVILEGED, 'p', OF_ANY) FN("privileged", FPRIVILEGED, 'p', OF_ANY)
/* -r restricted shell */ /* -r restricted shell */
FN("restricted", FRESTRICTED, 'r', OF_CMDLINE) FN("restricted", FRESTRICTED, 'r', OF_CMDLINE)
/* ./. called as sh (some POSIX, some kludgy) not mksh (non-standard) */
FN("sh", FSH, 0, OF_ANY)
/* -s (invocation) parse stdin (pseudo non-standard) */ /* -s (invocation) parse stdin (pseudo non-standard) */
FN("stdin", FSTDIN, 's', OF_CMDLINE) FN("stdin", FSTDIN, 's', OF_CMDLINE)

8
syn.c
View File

@ -22,7 +22,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.44 2009/09/26 03:40:02 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/syn.c,v 1.45 2009/10/02 18:08:37 tg Exp $");
struct nesting_state { struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */ int start_token; /* token than began nesting (eg, FOR) */
@ -591,7 +591,7 @@ casepart(int endtok)
musthave(')', 0); musthave(')', 0);
t->left = c_list(true); t->left = c_list(true);
/* Note: Posix requires the ;; */ /* Note: POSIX requires the ;; */
if ((tpeek(CONTIN|KEYWORD|ALIAS)) != endtok) if ((tpeek(CONTIN|KEYWORD|ALIAS)) != endtok)
musthave(BREAK, CONTIN|KEYWORD|ALIAS); musthave(BREAK, CONTIN|KEYWORD|ALIAS);
return (t); return (t);
@ -606,7 +606,7 @@ function_body(char *name,
bool old_func_parse; bool old_func_parse;
sname = wdstrip(name, false, false); sname = wdstrip(name, false, false);
/* Check for valid characters in name. posix and ksh93 say only /* Check for valid characters in name. POSIX and AT&T ksh93 say only
* allow [a-zA-Z_0-9] but this allows more as old pdkshs have * allow [a-zA-Z_0-9] but this allows more as old pdkshs have
* allowed more (the following were never allowed: * allowed more (the following were never allowed:
* nul space nl tab $ ' " \ ` ( ) & | ; = < > * nul space nl tab $ ' " \ ` ( ) & | ; = < >
@ -676,7 +676,7 @@ wordlist(void)
XPtrV args; XPtrV args;
XPinit(args, 16); XPinit(args, 16);
/* Posix does not do alias expansion here... */ /* POSIX does not do alias expansion here... */
if ((c = token(CONTIN|KEYWORD|ALIAS)) != IN) { if ((c = token(CONTIN|KEYWORD|ALIAS)) != IN) {
if (c != ';') /* non-POSIX, but AT&T ksh accepts a ; here */ if (c != ';') /* non-POSIX, but AT&T ksh accepts a ; here */
REJECT; REJECT;