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 -*-
|
||||
#-
|
||||
# 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
|
||||
|
||||
expected-stdout:
|
||||
@(#)MIRBSD KSH R50 2015/03/13
|
||||
@(#)MIRBSD KSH R50 2015/03/20
|
||||
description:
|
||||
Check version of shell.
|
||||
stdin:
|
||||
@ -39,7 +39,7 @@ name: KSH_VERSION
|
||||
category: shell:legacy-no
|
||||
---
|
||||
expected-stdout:
|
||||
@(#)LEGACY KSH R50 2015/03/13
|
||||
@(#)LEGACY KSH R50 2015/03/20
|
||||
description:
|
||||
Check version of legacy shell.
|
||||
stdin:
|
||||
@ -7522,6 +7522,20 @@ expected-stdout:
|
||||
name: aliases-funcdef-1
|
||||
description:
|
||||
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:
|
||||
alias foo='echo makro'
|
||||
foo() {
|
||||
@ -7534,6 +7548,20 @@ expected-stdout:
|
||||
name: aliases-funcdef-2
|
||||
description:
|
||||
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:
|
||||
alias foo='echo makro'
|
||||
foo () {
|
||||
@ -8699,28 +8727,87 @@ expected-exit: e != 0
|
||||
expected-stderr-pattern:
|
||||
/\.: missing argument.*\n.*\.: missing argument/
|
||||
---
|
||||
name: alias-function-no-conflict
|
||||
name: alias-function-no-conflict-legacy
|
||||
description:
|
||||
make aliases not conflict with functions
|
||||
note: for ksh-like functions, the order of preference is
|
||||
different; bash outputs baz instead of bar in line 2 below
|
||||
make aliases not conflict with functions, legacy version:
|
||||
undefine these aliases upon definition of the function
|
||||
note: for ksh functions, the order of preference differs in GNU bash
|
||||
category: shell:legacy-yes
|
||||
stdin:
|
||||
# POSIX function overrides and removes alias
|
||||
alias foo='echo bar'
|
||||
foo
|
||||
foo() {
|
||||
echo baz
|
||||
}
|
||||
foo
|
||||
unset -f foo
|
||||
foo 2>/dev/null || echo rab
|
||||
# alias overrides ksh function
|
||||
alias korn='echo bar'
|
||||
korn
|
||||
function korn {
|
||||
echo baz
|
||||
}
|
||||
foo
|
||||
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
|
||||
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:
|
||||
baz
|
||||
bar
|
||||
rab
|
||||
bar
|
||||
bar
|
||||
bar
|
||||
bar
|
||||
bfn
|
||||
bal
|
||||
bfn
|
||||
---
|
||||
name: bash-function-parens
|
||||
description:
|
||||
@ -8732,12 +8819,13 @@ stdin:
|
||||
echo "$1 {"
|
||||
echo ' echo "bar='\''$0'\'\"
|
||||
echo '}'
|
||||
echo ${2:-foo}
|
||||
print -r -- "${2:-foo}"
|
||||
}
|
||||
mk 'function foo' >f-korn
|
||||
mk 'foo ()' >f-dash
|
||||
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
|
||||
chmod +x f-*
|
||||
u=$(./f-argh)
|
||||
|
4
exec.c
4
exec.c
@ -23,7 +23,7 @@
|
||||
|
||||
#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
|
||||
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
|
||||
@ -1020,11 +1020,13 @@ define(const char *name, struct op *t)
|
||||
|
||||
nhash = hash(name);
|
||||
|
||||
#ifdef MKSH_LEGACY_MODE
|
||||
if (t != NULL && !tobool(t->u.ksh_func)) {
|
||||
/* drop same-name aliases for POSIX functions */
|
||||
if ((tp = ktsearch(&aliases, name, nhash)))
|
||||
ktdelete(tp);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (/* CONSTCOND */ 1) {
|
||||
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
|
||||
.\" Thorsten “mirabilos” Glaser <tg@mirbsd.org>
|
||||
@ -256,6 +256,17 @@ or
|
||||
mode and
|
||||
.Nm lksh
|
||||
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
|
||||
.Sh SEE ALSO
|
||||
.Xr mksh 1
|
||||
|
4
sh.h
4
sh.h
@ -169,9 +169,9 @@
|
||||
#endif
|
||||
|
||||
#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
|
||||
#define MKSH_VERSION "R50 2015/03/13"
|
||||
#define MKSH_VERSION "R50 2015/03/20"
|
||||
|
||||
/* arithmetic types: C implementation */
|
||||
#if !HAVE_CAN_INTTYPES
|
||||
|
Loading…
x
Reference in New Issue
Block a user