only lksh now implies unalias for a POSIX function definition (used e.g. in Debian sysvinit scripts that use a “stop” function)
This commit is contained in:
parent
8641829e21
commit
07898d8a45
112
check.t
112
check.t
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/check.t,v 1.686 2015/03/20 23:37:27 tg Exp $
|
# $MirOS: src/bin/mksh/check.t,v 1.687 2015/03/20 23:37:52 tg Exp $
|
||||||
# -*- mode: sh -*-
|
# -*- mode: sh -*-
|
||||||
#-
|
#-
|
||||||
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||||
@ -30,7 +30,7 @@
|
|||||||
# (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
|
# (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
|
||||||
|
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
@(#)MIRBSD KSH R50 2015/03/13
|
@(#)MIRBSD KSH R50 2015/03/20
|
||||||
description:
|
description:
|
||||||
Check version of shell.
|
Check version of shell.
|
||||||
stdin:
|
stdin:
|
||||||
@ -39,7 +39,7 @@ name: KSH_VERSION
|
|||||||
category: shell:legacy-no
|
category: shell:legacy-no
|
||||||
---
|
---
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
@(#)LEGACY KSH R50 2015/03/13
|
@(#)LEGACY KSH R50 2015/03/20
|
||||||
description:
|
description:
|
||||||
Check version of legacy shell.
|
Check version of legacy shell.
|
||||||
stdin:
|
stdin:
|
||||||
@ -7522,6 +7522,20 @@ expected-stdout:
|
|||||||
name: aliases-funcdef-1
|
name: aliases-funcdef-1
|
||||||
description:
|
description:
|
||||||
Check if POSIX functions take precedences over aliases
|
Check if POSIX functions take precedences over aliases
|
||||||
|
category: shell:legacy-no
|
||||||
|
stdin:
|
||||||
|
alias foo='echo makro'
|
||||||
|
foo() {
|
||||||
|
echo funktion
|
||||||
|
}
|
||||||
|
foo
|
||||||
|
expected-stdout:
|
||||||
|
makro
|
||||||
|
---
|
||||||
|
name: aliases-funcdef-1-legacy
|
||||||
|
description:
|
||||||
|
Check if POSIX functions take precedences over aliases
|
||||||
|
category: shell:legacy-yes
|
||||||
stdin:
|
stdin:
|
||||||
alias foo='echo makro'
|
alias foo='echo makro'
|
||||||
foo() {
|
foo() {
|
||||||
@ -7534,6 +7548,20 @@ expected-stdout:
|
|||||||
name: aliases-funcdef-2
|
name: aliases-funcdef-2
|
||||||
description:
|
description:
|
||||||
Check if POSIX functions take precedences over aliases
|
Check if POSIX functions take precedences over aliases
|
||||||
|
category: shell:legacy-no
|
||||||
|
stdin:
|
||||||
|
alias foo='echo makro'
|
||||||
|
foo () {
|
||||||
|
echo funktion
|
||||||
|
}
|
||||||
|
foo
|
||||||
|
expected-stdout:
|
||||||
|
makro
|
||||||
|
---
|
||||||
|
name: aliases-funcdef-2-legacy
|
||||||
|
description:
|
||||||
|
Check if POSIX functions take precedences over aliases
|
||||||
|
category: shell:legacy-yes
|
||||||
stdin:
|
stdin:
|
||||||
alias foo='echo makro'
|
alias foo='echo makro'
|
||||||
foo () {
|
foo () {
|
||||||
@ -8699,28 +8727,87 @@ expected-exit: e != 0
|
|||||||
expected-stderr-pattern:
|
expected-stderr-pattern:
|
||||||
/\.: missing argument.*\n.*\.: missing argument/
|
/\.: missing argument.*\n.*\.: missing argument/
|
||||||
---
|
---
|
||||||
name: alias-function-no-conflict
|
name: alias-function-no-conflict-legacy
|
||||||
description:
|
description:
|
||||||
make aliases not conflict with functions
|
make aliases not conflict with functions, legacy version:
|
||||||
note: for ksh-like functions, the order of preference is
|
undefine these aliases upon definition of the function
|
||||||
different; bash outputs baz instead of bar in line 2 below
|
note: for ksh functions, the order of preference differs in GNU bash
|
||||||
|
category: shell:legacy-yes
|
||||||
stdin:
|
stdin:
|
||||||
|
# POSIX function overrides and removes alias
|
||||||
alias foo='echo bar'
|
alias foo='echo bar'
|
||||||
|
foo
|
||||||
foo() {
|
foo() {
|
||||||
echo baz
|
echo baz
|
||||||
}
|
}
|
||||||
|
foo
|
||||||
|
unset -f foo
|
||||||
|
foo 2>/dev/null || echo rab
|
||||||
|
# alias overrides ksh function
|
||||||
alias korn='echo bar'
|
alias korn='echo bar'
|
||||||
|
korn
|
||||||
function korn {
|
function korn {
|
||||||
echo baz
|
echo baz
|
||||||
}
|
}
|
||||||
foo
|
|
||||||
korn
|
korn
|
||||||
|
# alias temporarily overrides POSIX function
|
||||||
|
bla() {
|
||||||
|
echo bfn
|
||||||
|
}
|
||||||
|
bla
|
||||||
|
alias bla='echo bal'
|
||||||
|
bla
|
||||||
|
unalias bla
|
||||||
|
bla
|
||||||
|
expected-stdout:
|
||||||
|
bar
|
||||||
|
baz
|
||||||
|
rab
|
||||||
|
bar
|
||||||
|
bar
|
||||||
|
bfn
|
||||||
|
bal
|
||||||
|
bfn
|
||||||
|
---
|
||||||
|
name: alias-function-no-conflict
|
||||||
|
description:
|
||||||
|
make aliases not conflict with function definitions
|
||||||
|
category: shell:legacy-no
|
||||||
|
stdin:
|
||||||
|
# POSIX function can be defined, but alias overrides it
|
||||||
|
alias foo='echo bar'
|
||||||
|
foo
|
||||||
|
foo() {
|
||||||
|
echo baz
|
||||||
|
}
|
||||||
|
foo
|
||||||
unset -f foo
|
unset -f foo
|
||||||
foo 2>/dev/null || echo rab
|
foo 2>/dev/null || echo rab
|
||||||
|
# alias overrides ksh function
|
||||||
|
alias korn='echo bar'
|
||||||
|
korn
|
||||||
|
function korn {
|
||||||
|
echo baz
|
||||||
|
}
|
||||||
|
korn
|
||||||
|
# alias temporarily overrides POSIX function
|
||||||
|
bla() {
|
||||||
|
echo bfn
|
||||||
|
}
|
||||||
|
bla
|
||||||
|
alias bla='echo bal'
|
||||||
|
bla
|
||||||
|
unalias bla
|
||||||
|
bla
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
baz
|
|
||||||
bar
|
bar
|
||||||
rab
|
bar
|
||||||
|
bar
|
||||||
|
bar
|
||||||
|
bar
|
||||||
|
bfn
|
||||||
|
bal
|
||||||
|
bfn
|
||||||
---
|
---
|
||||||
name: bash-function-parens
|
name: bash-function-parens
|
||||||
description:
|
description:
|
||||||
@ -8732,12 +8819,13 @@ stdin:
|
|||||||
echo "$1 {"
|
echo "$1 {"
|
||||||
echo ' echo "bar='\''$0'\'\"
|
echo ' echo "bar='\''$0'\'\"
|
||||||
echo '}'
|
echo '}'
|
||||||
echo ${2:-foo}
|
print -r -- "${2:-foo}"
|
||||||
}
|
}
|
||||||
mk 'function foo' >f-korn
|
mk 'function foo' >f-korn
|
||||||
mk 'foo ()' >f-dash
|
mk 'foo ()' >f-dash
|
||||||
mk 'function foo ()' >f-bash
|
mk 'function foo ()' >f-bash
|
||||||
mk 'function stop ()' stop >f-stop
|
# lksh can do without the backslash, too (cf. aliases-funcdef-2-legacy)
|
||||||
|
mk 'function stop ()' '\stop' >f-stop
|
||||||
print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
|
print '#!'"$__progname"'\nprint -r -- "${0%/f-argh}"' >f-argh
|
||||||
chmod +x f-*
|
chmod +x f-*
|
||||||
u=$(./f-argh)
|
u=$(./f-argh)
|
||||||
|
4
exec.c
4
exec.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.146 2015/02/19 22:26:49 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.147 2015/03/20 23:37:54 tg Exp $");
|
||||||
|
|
||||||
#ifndef MKSH_DEFAULT_EXECSHELL
|
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||||
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
||||||
@ -1020,11 +1020,13 @@ define(const char *name, struct op *t)
|
|||||||
|
|
||||||
nhash = hash(name);
|
nhash = hash(name);
|
||||||
|
|
||||||
|
#ifdef MKSH_LEGACY_MODE
|
||||||
if (t != NULL && !tobool(t->u.ksh_func)) {
|
if (t != NULL && !tobool(t->u.ksh_func)) {
|
||||||
/* drop same-name aliases for POSIX functions */
|
/* drop same-name aliases for POSIX functions */
|
||||||
if ((tp = ktsearch(&aliases, name, nhash)))
|
if ((tp = ktsearch(&aliases, name, nhash)))
|
||||||
ktdelete(tp);
|
ktdelete(tp);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
while (/* CONSTCOND */ 1) {
|
while (/* CONSTCOND */ 1) {
|
||||||
tp = findfunc(name, nhash, true);
|
tp = findfunc(name, nhash, true);
|
||||||
|
13
lksh.1
13
lksh.1
@ -1,4 +1,4 @@
|
|||||||
.\" $MirOS: src/bin/mksh/lksh.1,v 1.6 2015/03/20 23:37:29 tg Exp $
|
.\" $MirOS: src/bin/mksh/lksh.1,v 1.7 2015/03/20 23:37:54 tg Exp $
|
||||||
.\"-
|
.\"-
|
||||||
.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015
|
.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015
|
||||||
.\" Thorsten “mirabilos” Glaser <tg@mirbsd.org>
|
.\" Thorsten “mirabilos” Glaser <tg@mirbsd.org>
|
||||||
@ -256,6 +256,17 @@ or
|
|||||||
mode and
|
mode and
|
||||||
.Nm lksh
|
.Nm lksh
|
||||||
do not keep file descriptors \*(Gt 2 private from sub-processes.
|
do not keep file descriptors \*(Gt 2 private from sub-processes.
|
||||||
|
.It
|
||||||
|
.Nm lksh
|
||||||
|
undefines an alias when a
|
||||||
|
.Tn POSIX
|
||||||
|
function with the same name is defined,
|
||||||
|
to make that function immediately callable.
|
||||||
|
In
|
||||||
|
.Nm mksh ,
|
||||||
|
aliases have precedence; the name must be quoted or
|
||||||
|
.Ic unalias Ns ed
|
||||||
|
to access it.
|
||||||
.El
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr mksh 1
|
.Xr mksh 1
|
||||||
|
4
sh.h
4
sh.h
@ -169,9 +169,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#ifdef EXTERN
|
||||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.720 2015/03/20 21:46:41 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.721 2015/03/20 23:37:55 tg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#define MKSH_VERSION "R50 2015/03/13"
|
#define MKSH_VERSION "R50 2015/03/20"
|
||||||
|
|
||||||
/* arithmetic types: C implementation */
|
/* arithmetic types: C implementation */
|
||||||
#if !HAVE_CAN_INTTYPES
|
#if !HAVE_CAN_INTTYPES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user