tests: reference: don't rely on od's -w option
[gzip.git] / zless.in
blob1c98d7f1dd974a2332888b9cd85ba6dd53063443
1 #!/bin/sh
3 # Copyright (C) 1998, 2002, 2006-2007, 2010-2024 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 version="zless (gzip) @VERSION@
19 Copyright (C) 2024 Free Software Foundation, Inc.
20 This is free software. You may redistribute copies of it under the terms of
21 the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.
22 There is NO WARRANTY, to the extent permitted by law.
24 Written by Paul Eggert."
26 usage="Usage: $0 [OPTION]... [FILE]...
27 Like 'less', but operate on the uncompressed contents of any compressed FILEs.
29 Options are the same as for 'less'.
31 Report bugs to <bug-gzip@gnu.org>."
33 case $1 in
34 --help) printf '%s\n' "$usage" || exit 1; exit;;
35 --version) printf '%s\n' "$version" || exit 1; exit;;
36 esac
38 if test "${LESSMETACHARS+set}" != set; then
39 # Work around a bug in less 394 and earlier;
40 # it mishandles the metacharacters '$%=~'.
41 space=' '
42 tab=' '
43 newline='
45 LESSMETACHARS="$space$tab$newline'"';*?"()<>[|&^`#\$%=~'
46 export LESSMETACHARS
49 less_version=`less -V 2>/dev/null`
50 case $less_version in
51 less' '45[1-9]* | \
52 less' '4[6-9][0-9]* | \
53 less' '[5-9][0-9][0-9]* | \
54 less' '[1-9][0-9][0-9][0-9]*)
55 check_exit_status='|';;
56 *) check_exit_status='';;
57 esac
58 case $less_version in
59 less' '429* | \
60 less' '4[3-9][0-9]* | \
61 less' '[5-9][0-9][0-9]* | \
62 less' '[1-9][0-9][0-9][0-9]*)
63 use_input_pipe_on_stdin='-';;
64 *) use_input_pipe_on_stdin='';;
65 esac
66 case $less_version in
67 less' '623* | \
68 less' '62[4-9]* | \
69 less' '6[3-9][0-9]* | \
70 less' '[7-9][0-9][0-9]* | \
71 less' '[1-9][0-9][0-9][0-9]*)
72 show_preproc_error='--show-preproc-error';;
73 *) show_preproc_error='';;
74 esac
76 LESSOPEN="|$check_exit_status${use_input_pipe_on_stdin}'gzip' -cdfq -- %s"
77 export LESSOPEN
79 exec less $show_preproc_error "$@"