summary refs log tree commit diff
path: root/src/bltin/test.c (unfollow)
Commit message (Collapse)Author
2009-01-14Release 0.5.5.1.Herbert Xu
2009-01-14[BUILD] Add arith_yacc.h to dash_SOURCESHerbert Xu
The file arith_yacc.h was missing from dash_SOURCES causing it to be excluded from the generated tar file. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2009-01-13Release 0.5.5.Herbert Xu
2009-01-13[BUILD] Fixed build on OS XMark Mentovai
Hi, Herbert and friends. I've created a small patch that allows dash to be built on Mac OS X. I'm contributing it here with the hope that it's suitable for inclusion in dash. The changes in this patch are: - __attribute__((__alias__())) is not supported, add an autoconf check - open64 is not present although the stat64 family is, separate the autoconf checks - A syntax error had slipped into a non-glibc codepath - mkbuiltins had a nonportable mktemp invocation for the case where tempfile is not availalble Nothing in this patch is actually Mac OS X-specific, so it might aid portability to other platforms as well. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2009-01-13[BUILD] Fixed build on NetBSDAleksey Cheusov
Hi, I propose to apply the following patch for dash. The problem is alloca.h is absent on many platforms including NetBSD I'm running. Also, NetBSD's version of mktemp doesn't work without temporary filename pattern. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-10-17[MAN] Removed obsolete for loop syntaxHerbert Xu
Sven Mascheck reported that we no longer accept the non-standard for {} syntax but the manual page still refers to it. This patch removes that reference. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-08-05[CD] Fixed getcwd build error for the non-glibc caseHerbert Xu
On Sat, Aug 02, 2008 at 01:24:16AM +0200, Peter Hartlich wrote: > > dash's debian/diff/0048--CD-Restored-warning-when-getcwd-fails.diff > contains the following lines: > > - return getcwd(buf, sizeof(buf)) ? savestr(buf) : nullstr; > + > + if (getcwd(buf, sizeof(buf)) > + return savestr(buf); > > The if condition is missing a closing parenthesis, which probably went > unnoticed because it occurs in a section only compiled if __GLIBC__ is > not defined. This patch adds the extra parenthesis. Thanks Peter. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-07-13[MAN] Added missing right parenthesisGerrit Pape
In section Redirection the following text misses a left brace: where redir-op is one of the redirection operators mentioned previously. Following is a list of the possible redirections. The [n] is an optional number, as in \u20183\u2019 (not \u2018[3]\u2019, that refers to a file descriptor. Reported by Jörg Sommer through http://bugs.debian.org/481365 Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-07-13[OPTIONS] Added support for -lHerbert Xu
This patch adds support for the -l option (login shell) as required by the LSB. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-07-13[SHELL] Expand ENV before using itHerbert Xu
Per POSIX ENV needs to undergo parameter expansion. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-07-13[INPUT] Made setinputfd staticHerbert Xu
This function is no longer used anywhere else. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-07-13[BUILTIN] Made t_lex reentrantHerbert Xu
The previous two changes were broken because t_lex uses global state. This patch removes that by making t_wp local to t_lex. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-07-13[BUILTIN] Made aexpr/oexpr non-recursiveHerbert Xu
Making these functions non-recursive is straightforward since they carry no state. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-07-13[BUILTIN] Fixed 3,4-argument cases for test per POSIXHerbert Xu
----- Forwarded message from Gerrit Pape <pape@smarden.org> ----- Subject: Bug#455828: dash: 4-argument test "test \( ! -e \)" yields an error Date: Fri, 28 Dec 2007 08:53:29 +0000 From: Gerrit Pape <pape@smarden.org> To: Vincent Lefevre <vincent@vinc17.org>, 455828@bugs.debian.org On Thu, Dec 27, 2007 at 06:23:20PM +0100, Vincent Lefevre wrote: > On 2007-12-27 16:00:06 +0000, Gerrit Pape wrote: > > On Wed, Dec 12, 2007 at 02:18:47AM +0100, Vincent Lefevre wrote: > > > According to POSIX[*], "test \( ! -e \)" is a 4-argument test and is > > > here equivalent to "test ! -e". But dash (like ksh93 and bash) yields > > > an error: > > > > > > $ test \( ! -e \) || echo $? > > > test: 1: closing paren expected > > > 2 > > > $ test ! -e || echo $? > > > 1 > > > > Hi Vincent, > > > > the -e switch to test takes an argument, a pathname. > > According to POSIX, in both above examples, "-e" is *not* a switch, > just a string. > > test \( ! -e \) > > means: return true if the string "-e" is empty, otherwhise return false. > The error in dash is that it incorrectly thinks that "-e" is a switch in > this context. I see, you're right. Thanks, Gerrit. ----- End forwarded message ----- This patch hard-codes the 3,4-argument cases in the way required by POSIX. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-19[EXPAND] Fixed non-leading slash treatment in expmetaHerbert Xu
Back in January an attempt was made to fix the interpretation of quoted slashes in expmeta. However, this only fixed those cases where the quoted slash is at the front of the word. The case of non-leading slashes caused the previous directory part to gain a back slash suffix which causes subsequent pattern matches to fail. This patch fixes this by removing the back slash in that case. Thanks to Romain Tartière fox reporting this bug. Test case: echo /*"/null" Old result: /*/null New result: /dev/null Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-07[ARITH] Fixed lexical error on & and |Gerrit Pape
The parser used to skip a byte when parsing the & and | operators, testcase: $ dash -c 'echo $((7&1))' $ dash -c 'echo $((7& 1))' $ dash -c 'echo $((7&11))' Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-03[SHELL] Added gitignoreDan McGee
This gitignore covers most of the generated files in the src/ directory. Signed-off-by: Dan McGee <dpmcgee@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-03[SHELL] Use uninitialized_var to silence bogus warningsHerbert Xu
gcc generates bogus warnings about uninitialised variables in parser.c. This patch borrows the uninitialized_var macro from Linux to silence them. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-03[SHELL] Fixed klibc/klcc build problemsDan McGee
klibc does not have mempcpy, so system.h must be included where this is used to provide the replacement. glob.h doesn't exist, so we need to guard this include with the HAVE_GLOB definition. Finally, klcc didn't like the syntax of the main definition in mksignames, and the resulting program segfaulted when trying to dereference any part of the argv array. Updating the main function definition solved the problem. Signed-off-by: Dan McGee <dpmcgee@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-03[ERROR] Set default exvwarning2 arg0 for errors during early initialisationHerbert Xu
As it stands if we get an error before procargs gets called by main() we'll try to print out a null pointer. This patch avoids this by printing out "sh" instead. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-03[CD] Restored warning when getcwd failsHerbert Xu
Somewhere along the lines the warning when getcwd fails went missing. This patch restores it. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-03[CD] Test __GLIBC__ instead of _GNU_SOURCEHerbert Xu
AC_GNU_SOURCE always defines _GNU_SOURCE so testing it is pointless. This patch changes it to test __GLIBC__ instead. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-03[EXEC] Fixed _PATH_BSHELL warningHerbert Xu
With klcc we get klcc -DHAVE_CONFIG_H -I. -I.. -include ../config.h -DBSD=1 -DSHELL -DIFS_BROKEN -Wall -D__CTYPE_NO_INLINE -MT exec.o -MD -MP -MF .deps/exec.Tpo -c -o exec.o exec.c exec.c: In function 'tryexec': exec.c:160: warning: comparison with string literal results in unspecified behavior Storing it in a local variable fixes the problem. Thanks to Dan McGee for reporting this. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-02[CD] Restored non-glibc getcwd supportHerbert Xu
These days dash is expected to build with libraries other than glibc so we need to support the old way of calling getcwd again. Thanks to Dan McGee for reporting this bug when dash is built with klibc. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-02[JOBS] Fix cmdtxt crash on if statementsLarry Doolittle
(Herbert: for context, see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=467065 ) This is a real bug in upstream dash, which has existed since at least dash-0.5.1 (July 2004). It is a latent bug in cmdtxt() (which I think applies only to pipes) as it handles "if" commands. The attached patch fixes it for me. It's possible this patch will fix one or more of #462414, #462977, and #463649. I'll send messages there to see if the submitters can test. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2008-05-02[EXPAND] Fix slash treatment in expmetaHerbert Xu
The change [EXPAND] Do not quote back slashes in parameter expansions outside quotes triggered a latent bug in expmeta where the forward slashes when preceded by a blackslash weren't recognised as directory separators. This was hidden because a work-around was put in place for glob(3) which meant that we never had any backslashes immediately before forward slashes. This patch fixes the metaflag loop to recognise forward slashes even when they follow a backslash. Thanks to Daniel Hahler for reporting this problem. Test case: echo "/"root* Old result: /root* New result: /root Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2007-12-27[PARSER] Do not show prompts in expandstrHerbert Xu
Once I fixed the previous problem it became apparent that we never dealt with prompts with new-lines in them correctly. The problem is that we showed a secondary prompt for each of them. This patch disables prompt generation in expandstr. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2007-12-27[PARSER] Add FAKEEOFMARK for expandstrHerbert Xu
Previously expandstr used the string "" to indicate that it needs to be treated just like a here-doc except that there is no terminator. However, the string "" is in fact a valid here-doc terminator so now that we deal with it correctly expandstr no longer works in the presence of new-lines in the prompt. This patch introduces the FAKEEOFMARK macro which does not equal any real EOF marker but is distinct from the NULL pointer which is used to indicate non-here-doc contexts. Thanks to Markus Triska for reporting this regression. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2007-12-23[ARITH] If imaxdiv() isn't available, use / and % operatorsGerrit Pape
Although in posix, imaxdiv() isn't implemented on Debian/alpha, causing dash to fail to build. So use / and % operators if imaxdiv() isn't available. http://bugs.debian.org/456398 Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2007-12-23[BUILTIN] Add set +o supportRichard M Kreuter
The dash(1) in Debian stable does not support "set +o" in the manner specified by SUSv3: |+o | Write the current option settings to standard output in a format | that is suitable for reinput to the shell as commands that | achieve the same options settings. (citation from http://www.opengroup.org/onlinepubs/009695399/utilities/set.html) Instead, dash's "set +o" prints the shell's options in a human-readable format. Here is a simple test program that exercises this feature; it works as I believe is required under bash, but not under dash. # Save the shell's options set +o > /tmp/settings-commands set -o | sort > /tmp/settings-before # Change some options. set -v set -f set -x set +o emacs set -o vi # Try to restore our options. . /tmp/settings-commands set -o | sort > /tmp/settings-after # Compare. diff /tmp/settings-before /tmp/settings-after I believe the following small patch adds this feature to dash, and documents it in the manual page: Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2007-12-23[EVAL] Fix bad pointer arithmetic in evalcommandSteve Langasek
dash dies on sparc with a SIGBUS due to an arithmetic error introduced with commit 03b4958, this patch fixes it. --- > Hi Gerrit, > > dash 0.5.4-3 dies on sparc with a SIGBUS due to an arithmetic error > introduced with the patch > 0030-EXEC-Fixed-execing-of-scripts-with-no-hash-bang.diff. The > attached > patch fixes the problem. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2007-11-11[EXPAND] Expand here-documents in the current shell environmentHerbert Xu
Previously we always expanded here-documents in a subshell. This is contrary to the POSIX specification and how other shells behave. What's more this slows down many expansions due to the extra fork (however, it must be said that it is possible for it speed up certain expansions by running it simultaneously with the command on two CPUs). This patch move the expansion into the current shell environment. Test case: unset a cat <<- EOF > /dev/null ${a=NOT} EOF echo ${a}BAD Old result: BAD New result: NOTBAD
2007-11-11[EXPAND] Removed herefd hackHerbert Xu
The herefd hack goes back more than a decade. it limits the amount of memory we have to allocate when expanding here-documents by writing the result out from time to time. However, it's no longer safe because the stack is used to place intermediate results too and there we certainly don't want to write them out should we be short on memory. In any case, with today's computers we can afford to keep the entire result in memory and write them out at the end.
2007-11-11[PARSER] Removed noexpand/length check on eofmarkHerbert Xu
On Tue, Oct 30, 2007 at 04:23:35AM +0000, Oleg Verych wrote: > > } 8<<"" > ====================== Actually this (the empty delim) only works with dash by accident. I've tried bash and pdksh and they both terminate on the first empty line which is what you would expect rather than EOF. The real Korn shell does something completely different. I've fixed this in dash to conform to bash/pdksh. > In [0] it's stated, that delimiter isn't evaluated (expanded), only > quoiting must be checked. That if() seems to be completely bogus. OK I agree. The reason it was there is because the parser would have already replaced the dollar sign by an internal representation. I've fixed it properly with this patch. Test case: cat <<- $a OK $a cat <<- "" OK echo OK Old result: dash: Syntax error: Illegal eof marker for << redirection OK echo OK New result: OK OK OK
2007-10-20[PARSER] Fix here-doc corruptionHerbert Xu
The change [PARSER] Recognise here-doc delimiters terminated by EOF introduced a regerssion whereby lines starting with eofmark but are not equal to eofmark would be corrupted. This patch fixes it. Test case: cat << _ACEOF _ASBOX _ACEOF Old result: SASBOX New result: _ASBOX
2007-10-20[EXPAND] Added configure --enable-glob and --enable-fnmatch optionsHerbert Xu
Debian's libc6 as of 2.6.1-6 has working glob(3)/fnmatch(3) support. This patch adds the options --enable-glob and --enable-fnmatch to the configure script. By default glob(3) and fnmatch(3) are still unused. However, on distros where the glibc is known to work you may enable these options.
2007-10-17[SHELL] Replace shared illnum message by badnum function.Herbert Xu
This patch adds the badnum function and uses it to mostly replace the use of illnum except in miscbltin where the current code turns out to be smaller because of the twin sh_error calls.
2007-10-17[BUILTIN] Disallow completely blank strings in non-arithmetic context.Oleg Verych
* NULL as a number argument: olecom@deen:/mnt/debian/src/dash-0.5.3$ time src/dash tst-01.sh test: 20: `': bad number `' eq 0: 2 must be >1, Not A Number test: 20: `': bad number `' ne 0: 2 must be >1, Not A Number test: 20: `': bad number `' gt 0: 2 must be >1, Not A Number test: 20: `': bad number `' ge 0: 2 must be >1, Not A Number test: 20: `': bad number `' lt 0: 2 must be >1, Not A Number test: 20: `': bad number `' le 0: 2 must be >1, Not A Number /usr/bin/test: invalid integer `' `' eq 0: 2 must be >1, Not A Number /usr/bin/test: invalid integer `' `' ne 0: 2 must be >1, Not A Number /usr/bin/test: invalid integer `' `' gt 0: 2 must be >1, Not A Number /usr/bin/test: invalid integer `' `' ge 0: 2 must be >1, Not A Number /usr/bin/test: invalid integer `' `' lt 0: 2 must be >1, Not A Number /usr/bin/test: invalid integer `' `' le 0: 2 must be >1, Not A Number #!/usr/bin/printf This not executable script%c\n test_arithm() { for aop in eq ne gt ge lt le do "$1" 0 -$aop "$NOTHING" echo "\`' $aop 0:" $? " must be >1, Not A Number" done } # opengroup.org/onlinepubs/000095399/utilites/test.html (nothing about long): test_arithm test test_arithm /usr/bin/test # shend
2007-10-15[EXEC] Fixed execing of scripts with no hash-bangHerbert Xu
The function tryexec used the original name instead of the path found through PATH search. This patch fixes that. Test case: trap 'rm -f $TMP' EXIT TMP=$(tempfile -s nosuchthing) cat <<- EOF > $TMP echo OK EOF chmod u+x $TMP cd / PATH=${TMP%/*} ${TMP##*/} Old result: /bin/sh: Can't open filelgY4Fanosuchthing New result: OK
2007-10-11[BUILTIN] Use setvarint to set OPTINDHerbert Xu
This patch adds a flag argument to setvarint and uses it to set the OPTIND variable.
2007-10-11[EXPAND] Add likely flags in expariHerbert Xu
The case where the expansion isn't quoted is the norm.
2007-10-11[ARITH] Size optimisations in arithmetic lexerHerbert Xu
Use += instead of straight assignment for token value.
2007-10-11[ARITH] Add assignment and intmax_t supportHerbert Xu
This patch adds assignment operator support in arithmetic expansions. It also changes the type used to intmax_t.
2007-10-08[PARSER] Report substition errors at expansion timeHerbert Xu
On Wed, Apr 11, 2007 at 01:24:21PM -0700, Micah Cowan wrote: > Package: dash > Version: 0.5.3-3 > > Bug first reported against Ubuntu at > https://bugs.launchpad.net/ubuntu/+source/dash/+bug/105634 > by Paul Smith > > The description and some comments from that bug report follow. > > ----- > > This operation fails on Ubuntu: > > $ /bin/sh -c 'if false; then d="${foo/bar}"; fi' > /bin/sh: Syntax error: Bad substitution > > When used with other POSIX shells it succeeds. While semantically the > variable reference ${foo/bar} is not valid, this is not a syntax error > according to POSIX, and since the variable assignment expression is > never invoked (because it's within an "if false") it should not be seen > as an error. > > I ran into this because after restarting my system I could no longer log > in. It turns out that the problem was (a) I had edited .gnomerc to > source my .bashrc file so that my environment would be set properly, and > (b) I had added some new code to my .bashrc WITHIN A CHECK FOR BASH! > that used bash's ${var/match/sub} feature. Even though this code was > within a "case $BASH_VERSION; in *[0-9]*) ... esac (so dash would never > execute it since that variable is not set), it still caused dash to > throw up. > > ----- > > FYI, some relevant details from POSIX: > > Section 2.3, Token Recognition: > > 5. If the current character is an unquoted '$' or '`', the shell shall > identify the start of any candidates for parameter expansion ( Parameter > Expansion), command substitution ( Command Substitution), or arithmetic > expansion ( Arithmetic Expansion) from their introductory unquoted > character sequences: '$' or "${", "$(" or '`', and "$((", respectively. > The shell shall read sufficient input to determine the end of the unit > to be expanded (as explained in the cited sections). > > Section 2.6.2, Parameter Expansion: > > The format for parameter expansion is as follows: > > ${expression} > > where expression consists of all characters until the matching '}'. Any > '}' escaped by a backslash or within a quoted string, and characters in > embedded arithmetic expansions, command substitutions, and variable > expansions, shall not be examined in determining the matching '}'. > > [...] > > The parameter name or symbol can be enclosed in braces, which are > optional except for positional parameters with more than one digit or > when parameter is followed by a character that could be interpreted as > part of the name. The matching closing brace shall be determined by > counting brace levels, skipping over enclosed quoted strings, and > command substitutions. > > --- > > In addition to bash I've checked Solaris /bin/sh and ksh and they don't > report an error. > > ----- > Micah Cowan: > > The applicable portion of POSIX is in XCU 2.10.1: > > "The WORD tokens shall have the word expansion rules applied to them > immediately before the associated command is executed, not at the time > the command is parsed." > > This seems fairly clear to me. This patch moves the error detection to expansion time. Test case: if false; then echo ${a!7} fi echo OK Old result: dash: Syntax error: Bad substitution New result: OK
2007-10-06[BUILTIN] Use intmax_t arithmetic in testHerbert Xu
This patch adds the function atomax10 and uses it in test(1) so that we support intmax_t comparisons.
2007-10-06[VAR] Remove setvarsafeHerbert Xu
The only user of setvarsafe is getopts. However, we can achieve the same result by pre-setting the value of shellparam.optind.
2007-10-06[BUILTIN] Treat OPTIND=0 in the same way as OPTIND=1Herbert Xu
Previously setting OPTIND to 0 would cause subsequent getopts calls to fail. This patch makes dash reset the getopts parameters the same way as OPTIND=1. Both behaviours are allowed by POSIX but other common shells do tolerate this case.
2007-10-06[MEMALLOC] Add pushstackmarkHerbert Xu
This patch gets rid of the stack mark tracking hack by allocating a little bit of stack memory if we're at risk of planting a stack mark which may be grown later. To do this a new function pushstackmark is added which lets the user pick a bigger amount to allocate since some users do that anyway after setting a stack mark.
2007-10-05[MEMALLOC] Made grabstackblock an inline wrapper for stallocHerbert Xu
The function grabstackblock is identical in semantics to stalloc within its input constraints.
2007-10-04[PARSER] Size optimisations in parameter expansion parserHerbert Xu
Merge flags into subtype. Do not write subtype out twice. Add likely flag on ${ vs. $NAME. Kill unnecessary (and bogus) PEOA check.