diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2005-01-13 10:34:17 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2005-01-13 10:34:17 +0000 |
commit | ec4aa9f4093b5a063651caeb9f9520afc5369958 (patch) | |
tree | 8311fafa2dea69e1be39d8057e4edf626df42af7 | |
parent | 81b9354238e5457fe94a8d9ec466ed6e7529638e (diff) | |
download | zsh-ec4aa9f4093b5a063651caeb9f9520afc5369958.tar.gz zsh-ec4aa9f4093b5a063651caeb9f9520afc5369958.tar.xz zsh-ec4aa9f4093b5a063651caeb9f9520afc5369958.zip |
20698: Fix tail for POSIX conformance
-rw-r--r-- | ChangeLog | 5 | ||||
-rwxr-xr-x | Test/ztst.zsh | 30 |
2 files changed, 32 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog index f4ca8d4a7..3a2f5e06f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-01-13 Peter Stephenson <pws@csr.com> + + * 20698: Test/ztst.zsh: improve 20692 by using tail function + to overcome POSIX problems. + 2005-01-12 Oliver Kiddle <opk@zsh.org> * 20701: Src/system.h: fix compilation on Mac OS X diff --git a/Test/ztst.zsh b/Test/ztst.zsh index 3e6246958..388661976 100755 --- a/Test/ztst.zsh +++ b/Test/ztst.zsh @@ -28,9 +28,6 @@ emulate -R zsh [[ -n $LC_COLLATE ]] && LC_COLLATE=C [[ -n $LANG ]] && LANG=C -# POSIXLY_CORRECT can cause spurious error messages with "tail -<num>". -unset POSIXLY_CORRECT - # Set the module load path to correspond to this build of zsh. # This Modules directory should have been created by "make check". [[ -d Modules/zsh ]] && module_path=( $PWD/Modules ) @@ -60,6 +57,33 @@ ZTST_testname=$1 integer ZTST_testfailed +# This is POSIX nonsense. Because of the vague feeling someone, somewhere +# may one day need to examine the arguments of "tail" using a standard +# option parser, every Unix user in the world is expected to switch +# to using "tail -n NUM" instead of "tail -NUM". Older versions of +# tail don't support this. +tail() { + emulate -L zsh + + if [[ -z $TAIL_SUPPORTS_MINUS_N ]]; then + local test + test=$(echo "foo\nbar" | command tail -n 1 2>/dev/null) + if [[ $test = bar ]]; then + TAIL_SUPPORTS_MINUS_N=1 + else + TAIL_SUPPORTS_MINUS_N=0 + fi + fi + + integer argi=${argv[(i)-<->]} + + if [[ $argi -le $# && $TAIL_SUPPORTS_MINUS_N = 1 ]]; then + argv[$argi]=(-n ${argv[$argi][2,-1]}) + fi + + command tail "$argv[@]" +} + # The source directory is not necessarily the current directory, # but if $0 doesn't contain a `/' assume it is. if [[ $0 = */* ]]; then |