mirror of
https://github.com/MirBSD/mksh.git
synced 2025-12-31 06:07:17 +00:00
No description
functions taking parameters; from a discussion with and for @navi@vlhl.dev via https://social.vlhl.dev/objects/1bc8db98-19ea-4cec-ac2c-2ab3a22a1661 general idea is: | function (a b=foo) name { … } … is identical enough to… | function name { | a=$1; shift | if (( $# )); then | b=$1; shift | else | b=foo | fi | … | } … and the following hold: - the parenthesēs are needed; within, words are parsed, and whitespace (and even line continuations: function (⏎↹x⏎ ) name { … } is allowed) - degrading to bash-style 'function () name () { … }' is not allowed - this is only allowed for ksh-style functions, which, among other things, also do things like reset the shell flags on exit - the words must begin with a variable name and an equals sign, unquoted, or be comprised solely of such variable name - arrays are NOT supported to avoid surprises: x[$(exploit; echo 0)] - these are checked at definition time - words without equals sign are mandatory parameters - words with equals sign are optional parameters - if the corresponding argument is missing, the RHS is substituted - which may be empty: function (x=) name - which is ONLY evaluated in that case and not if not used - if you put mandatory parameters behind optional parameters, SOL - there is no nil value the user can use to get the default anyway - this considers variables as set and empty-or-not only, not unset - errors (missing required argument) report for the lineno of the function invocation - set -x output shows local=…;shift on the lineno of the definition - restricted mode is honoured this commit also reduces the amount of “volatile” in use, as a side bonus |
||
|---|---|---|
| Build.sh | ||
| check.pl | ||
| check.t | ||
| dot.mkshrc | ||
| edit.c | ||
| emacsfn.h | ||
| eval.c | ||
| exec.c | ||
| expr.c | ||
| exprtok.h | ||
| FAQ2HTML.sh | ||
| funcs.c | ||
| histrap.c | ||
| jehanne.c | ||
| jobs.c | ||
| lalloc.c | ||
| lex.c | ||
| lksh.1 | ||
| main.c | ||
| Makefile | ||
| mbsdcc.h | ||
| mbsdint.h | ||
| mirhash.h | ||
| misc.c | ||
| mksh.1 | ||
| mksh.faq | ||
| mksh.ico | ||
| os2.c | ||
| rlimits.opt | ||
| sh.h | ||
| sh_flags.opt | ||
| shf.c | ||
| strlcpy.c | ||
| syn.c | ||
| tree.c | ||
| ulimit.c | ||
| ulimits.opt | ||
| var.c | ||
| var_spec.h | ||