summaryrefslogtreecommitdiffstats
path: root/bin/ksh (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Provide definition of CTRL in vi.c like we do for emacs.c.millert2021-03-121-1/+4
| | | | Fixes a portability issue. From Benjamin Baier
* groff complains about the word "An" in an Rs/Re block, believing it a macro,jmc2021-03-111-3/+3
| | | | so escape it;
* Add support for ^R (redraw) in insert mode too.millert2021-03-102-3/+9
| | | | From gotroyb127, OK tb@
* Fix redrawing of a multiline PS1 prompt in vi mode.millert2021-03-101-8/+9
| | | | From gotroyb127 OK tb@
* use a journal reference instead of cstr when possiblejsg2021-03-081-1/+9
|
* Add some references, most of these were removed when we stopped buildingjsg2021-03-081-2/+11
| | | | | | and installing USD/SMM/PSD docs. jmc@ agrees with the direction, ok millert@ on an earlier diff
* Fix old ksh bug: wrong variable being looked up when value is provided.zhuk2021-03-051-2/+2
| | | | | | | This results, e.g., in allowing the first item of a read-only array to be overwritten, as found by Jordan Geoghegan. okay tb@
* In lib/libc/gen/charclass.h r1.3 guenther made cclasses const.tb2020-10-261-2/+2
| | | | | | | | Mark the pointer used to walk the array in ksh const as well. From Matthew Martin ok guenther
* Clear screen before redrawing the line with ^L, also in input mode.millert2020-09-202-29/+62
| | | | | | This is similar to the emacs mode clear-screen command. Unlike bash, but like zsh, ^L also works in input mode, not just command mode. OK kn@ tb@
* Fix "$@" splitting with empty IFStb2020-09-131-17/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | One uncommon but useful way of writing shell scripts is to start off by disabling field/word splitting (IFS='') and pathname expansion/globbing (set -f), re-enabling either or both only for the commands that need them, e.g. within a subshell. This helps avoid a lot of snags with field splitting and globbing if you forget to quote a variable somewhere, adding to the general robustness of a script. (In fact it eliminates much of the need to quote variable/parameter expansions, with empty removal remaining as the only issue.) Unfortunately OpenBSD ksh (like all pdksh variants except mksh) has a POSIX compliance bug that is a show stopper for this approach: "$@" does not generate words (arguments) if IFS is empty. As a result, the separate command arguments represented by "$@" become a single argument. So passing on an intact set of positional parameters to a command or function is impossible with field splitting disabled. Of course this is illogical: the quoted special parameter "$@" generates zero or more words, it doesn't split any words, so the contents of IFS (or lack thereof) should be neither here nor there. It's old ksh88 behaviour copied by the original pdksh, but it violates POSIX and it has been fixed many years ago in ksh93 and all other POSIX shells. From Martijn Dekker (who also wrote the above paragraphs) back in 2016. Thanks to Avi Halachmi for reminding us of the issue. ok czarkoff deraadt kn
* Collapse consecutive stars to avoid exponential behavior.millert2020-07-221-1/+4
| | | | OK tb@
* Add support for set -o pipefailjca2020-07-074-7/+41
| | | | | | | | | | | | | | | | With the pipefail option set, the exit status of a pipeline is 0 if all commands succeed, or the return status of the rightmost command that fails. This can help stronger error checking, but is not a silver bullet. For example, commands will exhibit a non-zero exit status if they're killed by a SIGPIPE when writing to a pipe. Yet pipefail was considered useful enough to be included in the next POSIX standard. This implementation remembers the value of the pipefail option when a pipeline is started, as described as option 1) in https://www.austingroupbugs.net/view.php?id=789#c4102 Requested by ajacoutot@, ok millert@
* Fix the exit code when eval()uating a || compound list, it wouldbenno2020-05-221-1/+7
| | | | | | | terminate the shell when running under -e. See also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=269067 and Bug reported including fix by Leah Neukirchen, Thanks! ok millert@
* Use proper function pointer type instead of void *jca2020-05-081-5/+7
| | | | | | | | | | Mixing up function and void pointers isn't defined by POSIX or the C standard. POSIX only specifies that casting the result of dlsym(3) to an appropriate function pointer works. Avoid all this by using a typedef. from Michael Forney, ok tb@
* Enforce that TMOUT is an integer literal to prevent command execution fromtb2020-02-211-1/+5
| | | | | | | | | | | the environment at shell initialization time. During startup, ksh calls 'eval typeset -i TMOUT="${TMOUT:-0}"'. which allows command injection via arithmetic expansion, e.g., by setting TMOUT to 'x[`/bin/echo Hi >&2`]'. Problem noted by Andras Farkas and tj, inspired by a similar issue in AT&T's ksh. Tested in snaps for two weeks. "go for it" deraadt
* some corrections to CDPATH;jmc2019-11-261-4/+6
| | | | from chohag
* No need for <sys/uio.h> as writev(2) isn't used any more.jca2019-10-271-2/+1
|
* Don't fail hard if we can't preallocate history storage.jca2019-10-271-7/+15
| | | | | | | | | | | Using alloc.c for the history array brings no value and prevents easy handling of memory shortage. Switch to plain reallocarray and keep running if HISTSIZE is too big. The allocation is still done upfront with no sanity checking, it would probably be nicer to allocate space as needed. Issue reported by thomas@habets.se who suggested a different approach.
* Add #include <stdlib.h> for mkstemp.bcallah2019-07-241-1/+2
| | | | | | Spotted by maya@netbsd ok deraadt@
* When system calls indicate an error they return -1, not some arbitraryderaadt2019-06-2814-65/+65
| | | | | | value < 0. errno is only updated in this case. Change all (most?) callers of syscalls to follow this better, and let's see if this strictness helps us in the future.
* Some asprintf() calls were checked < 0, rather than the precise == -1.deraadt2019-06-271-3/+3
| | | | ok millert nicm tb, etc
* Fix spellingjca2019-06-241-2/+2
|
* Partial revert of rev. 1.151:schwarze2019-06-241-5/+7
| | | | | | | Reference the First Edition (1989) of Bolsky/Korn which is about ksh88, the shell the OpenBSD ksh(1) descends from (via pdksh). The Second Edition (1995) of the book is about ksh93 which we don't provide. Pointed out by Andras Farkas on bugs@.
* zap trailing whitespace;jmc2019-06-211-3/+3
|
* Allow string greater/less than than operators to work with test aka [.millert2019-06-192-12/+14
| | | | | | Previously they were only recognized in [[ ... ]] expressions. This changes sh/ksh to be consistent with test(1) as well as shells like bash and dash. OK jca@ jmc@
* mention that using vi command line editing mode requires enabling it;schwarze2019-05-221-3/+7
| | | | | omission reported by Rudolf Sykora <rsykora at disroot dot org> on misc@; tweak and OK jmc@
* Bind ^L (C-l) to clear-screen instead of redrawjca2019-04-032-6/+6
| | | | | Slightly more useful for some, same defaults as bash. No objection deraadt@ phessler@, ok tb@ kn@ benno@
* When evaluating an arithmetical expression, for example inside $(()),schwarze2019-02-204-4/+14
| | | | | | | | | | | | | | | | | | | never do substitution (neither parameter, nor command, nor arithmetic, nor tilde substitution) on the values of any variables encountered inside the expression, but do recursively perform arithmetical evaluation of subexpressions as required. This makes behaviour more consistent, without hindering any behaviour promised in the manual page. A quirk originally reported by Andy Chu <andychup at gmail dot com> was that in the past, when encountering an array index, the shell would not only do evaluation, but also substitution on the array index, even though substitution would not be done on the expression in general. tobias@ contributed to initial efforts of understanding the quirk. patch tested in a bulk build by naddy@ "please commit" deraadt@
* I am retiring my old email address; replace it with my OpenBSD one.millert2019-01-251-2/+2
|
* Fix three more buglets:schwarze2019-01-141-2/+6
| | | | | | | | | | | | 1. Another off-by-one: if a mail file name ends in an (escaped) percent sign, do not forget to check whether the next byte is the percent sign introducing the message (MAILPATH='filename\%%msg'). 2. If the message is empty, use the default message rather than printing a blank line (MAILPATH='filename%'). 3. If the file name is empty, don't bother with mballoc(): the subsequent stat(2) can never succeed. (MAILPATH='%msg'). Found while reviewing the previous commit by tedu@. OK tedu@.
* do not peek before the beginning of a stringtedu2019-01-141-2/+2
| | | | ok deraadt schwarze tb
* short circuit mail check if MAIL is unset. ok antontedu2019-01-071-8/+10
|
* Delete unnecessary <libgen.h> #includesguenther2018-12-301-2/+1
| | | | ok deraadt@
* Tweak the syntax displays to show that the list of wordsschwarze2018-12-162-11/+13
| | | | | | | in "for name in [word ...]; do list; done" can be empty. In sh(1), clarify what happens in that case. In ksh(1), clarify how it can happen that the list is never executed. OK jmc@ tb@
* Fix kill [-SIGNAME | -s SIGNAME] and simplifyjca2018-12-081-13/+11
| | | | | | While the code intended to support both -s NAME and -s SIGNAME, the tests performed were wrong. Replace convoluted code with less cryptic conditionals. ok anton@
* in getopts, when a option is followed by a colon the parameter is mandatorysolene2018-11-301-3/+3
| | | | ok guenther@ deraadt@
* Convert the pledge call to idiomatic format 'cause we love grep.deraadt2018-11-201-3/+4
|
* Fix the case where the recursion detection isn't reset when the command ismartijn2018-11-203-9/+21
| | | | | | | interrupted. Lots of back and forth with anton@ OK jca@, tb@, anton@
* Use a very regular call pattern to pledge, so that we can continue toderaadt2018-11-171-10/+11
| | | | grep and compare the use in all programs..
* Include "id" in pledge (for setres[ug]id, setgroups) if the shell isnicm2018-11-162-5/+18
| | | | | | | privileged and remove it when dropping privileges (set +p), setting a flag to make sure we don't do it again. ok deraadt millert
* Export the PWD and OLDPWD shell variables as per POSIX.millert2018-09-291-2/+2
| | | | | Previously, these would only be exported if they were present in the environment when the shell started. OK deraadt@ anton@ kn@
* Contrary to the sh manual, it is possible to modify the PWD variablemillert2018-09-281-3/+2
| | | | (and this is allowed by POSIX). OK deraadt@ kn@
* Second attempt of the recently backed out variable expansion fix. This time withanton2018-07-091-4/+35
| | | | | | a missing NULL check added by jca@ which fixes the segfault in the installer. ok jca@ tb@
* Back out previous. naddy and rpe found that it breaks the installer withtb2018-07-081-35/+4
| | | | | | install.sub's ${*:+$*} substitution in addel(). ok jca
* Fix a bug related to variable expansion referencing multiple read-onlyanton2018-07-081-4/+35
| | | | | | | | | | | variables; such as positional arguments. Since global() returns a pointer to static storage for read-only variables, the memory pointed to needs to be copied to prevent any subsequent call to global() to override the previously accessed variable. Bug reported by Andreas Kusalananda Kähäri on bugs@ ok benno@ jca@ tb@
* Count $MAILCHECK with the monotonic clock.cheloha2018-06-251-6/+11
| | | | | | | So that ksh still looks for new mail every $MAILCHECK seconds, even if the system clock is rolled backward. ok anton@
* Use shl_out->fd instead of STDOUT_FILENO in the call the setupterm().millert2018-06-181-2/+2
| | | | Suggested by anton@
* Add clear-screen emacs editing command, currently not bound to amillert2018-06-187-17/+72
| | | | | key by default. The shell will query the terminfo database to find the escape sequence to clear the screen. OK deraadt@
* point readers to the correct place instead of having thembenno2018-05-301-4/+4
| | | | | | jump around. suggested and ok jmc@, ok jcm@
* remove the alias type='whence -v' and replace it withbenno2018-05-184-11/+38
| | | | | | | | | a buildin command, that just calls into c_whence(). This makes type look like the buildin in other shells and makes things like system("'type' 'git'"); work. With lots of suggestions and feedback from anton@, kn@ and jca@. ok kn@ jca@