Problem reported by Bruno Haible (Bug#29266#20).
* NEWS: Mention this.
* gunzip.in, gzexe.in, zcat.in, zcmp.in, zdiff.in, zforce.in:
* zgrep.in, zless.in, zmore.in, znew.in:
Use printf instead of echo if the argument might contain ‘\’, at
least in theory. Don’t assume printf exits with status 1 on
failure; it might be some other positive status.
* gzexe.in: Use printf consistently instead of echo, and
proscribe it instead of echo.
1970 and after 2106, and timestamps after 2038 on platforms with
32-bit signed time_t. [bug present since the beginning]
+ Commands implemented via shell scripts are now more consistent about
+ failure status. For example, 'gunzip --help >/dev/full' now
+ consistently exits with status 1 (error), instead of with status 2
+ (warning) on some platforms. [bug present since the beginning]
+
Support for VMS and Amiga has been removed. It was not working anyway,
and it reportedly caused file name glitches on MS-Windowsish platforms.
Report bugs to <bug-gzip@gnu.org>."
case $1 in
---help) exec echo "$usage";;
---version) exec echo "$version";;
+--help) printf '%s\n' "$usage" || exit 1; exit;;
+--version) printf '%s\n' "$version" || exit 1; exit;;
esac
exec gzip -d "$@"
while :; do
case $1 in
-d) decomp=1; shift;;
- --h*) exec echo "$usage";;
- --v*) exec echo "$version";;
+ --h*) printf '%s\n' "$usage" || exit 1; exit;;
+ --v*) printf '%s\n' "$version" || exit 1; exit;;
--) shift; break;;
*) break;;
esac
done
if test $# -eq 0; then
- echo >&2 "$0: missing operand
+ printf >&2 '%s\n' "$0: missing operand
Try \`$0 --help' for more information."
exit 1
fi
esac
if test ! -f "$file" || test ! -r "$file"; then
res=$?
- echo >&2 "$0: $i is not a readable regular file"
+ printf >&2 '%s\n' "$0: $i is not a readable regular file"
continue
fi
if test $decomp -eq 0; then
if sed -e 1d -e 2q "$file" | grep "^skip=[0-9][0-9]*$" >/dev/null; then
- echo >&2 "$0: $i is already gzexe'd"
+ printf >&2 '%s\n' "$0: $i is already gzexe'd"
continue
fi
fi
if test -u "$file"; then
- echo >&2 "$0: $i has setuid permission, unchanged"
+ printf >&2 '%s\n' "$0: $i has setuid permission, unchanged"
continue
fi
if test -g "$file"; then
- echo >&2 "$0: $i has setgid permission, unchanged"
+ printf >&2 '%s\n' "$0: $i has setgid permission, unchanged"
continue
fi
case /$file in
*/basename | */bash | */cat | */chmod | */cp | \
- */dirname | */echo | */expr | */gzip | \
- */ln | */mkdir | */mktemp | */mv | */rm | \
+ */dirname | */expr | */gzip | \
+ */ln | */mkdir | */mktemp | */mv | */printf | */rm | \
*/sed | */sh | */sleep | */test | */tail)
- echo >&2 "$0: $i might depend on itself"; continue;;
+ printf >&2 '%s\n' "$0: $i might depend on itself"; continue;;
esac
dir=`dirname "$file"` || dir=$TMPDIR
tmp=$dir/gzexe$$
fi && { cp -p "$file" "$tmp" 2>/dev/null || cp "$file" "$tmp"; } || {
res=$?
- echo >&2 "$0: cannot copy $file"
+ printf >&2 '%s\n' "$0: cannot copy $file"
continue
}
if test -w "$tmp"; then
writable=0
chmod u+w "$tmp" || {
res=$?
- echo >&2 "$0: cannot chmod $tmp"
+ printf >&2 '%s\n' "$0: cannot chmod $tmp"
continue
}
fi
*/*) gztmp=$gztmpdir/`basename "$0"`;;
esac || { (exit 127); exit 127; }
-case `echo X | tail -n +1 2>/dev/null` in
+case `printf 'X\n' | tail -n +1 2>/dev/null` in
X) tail_n=-n;;
*) tail_n=;;
esac
(sleep 5; rm -fr "$gztmpdir") 2>/dev/null &
"$gztmp" ${1+"$@"}; res=$?
else
- echo >&2 "Cannot decompress $0"
+ printf >&2 '%s\n' "Cannot decompress $0"
(exit 127); res=127
fi; exit $res
EOF
gzip -cv9 "$file") > "$tmp" || {
res=$?
- echo >&2 "$0: compression not possible for $i, file unchanged."
+ printf >&2 '%s\n' "$0: compression not possible for $i, file unchanged."
continue
}
skip=[0-9] | skip=[0-9][0-9] | skip=[0-9][0-9][0-9])
eval "$skip_line";;
esac
- case `echo X | tail -n +1 2>/dev/null` in
+ case `printf 'X\n' | tail -n +1 2>/dev/null` in
X) tail_n=-n;;
*) tail_n=;;
esac
tail $tail_n +$skip "$file" | gzip -cd > "$tmp" || {
res=$?
- echo >&2 "$0: $i probably not in gzexe format, file unchanged."
+ printf >&2 '%s\n' "$0: $i probably not in gzexe format, file unchanged."
continue
}
fi
test $writable -eq 1 || chmod u-w "$tmp" || {
res=$?
- echo >&2 "$0: $tmp: cannot chmod"
+ printf >&2 '%s\n' "$0: $tmp: cannot chmod"
continue
}
ln -f "$file" "$file~" || {
res=$?
- echo >&2 "$0: cannot backup $i as $i~"
+ printf >&2 '%s\n' "$0: cannot backup $i as $i~"
continue
}
mv -f "$tmp" "$file" || {
res=$?
- echo >&2 "$0: cannot rename $tmp to $i"
+ printf >&2 '%s\n' "$0: cannot rename $tmp to $i"
continue
}
tmp=
Report bugs to <bug-gzip@gnu.org>."
case $1 in
---help) exec echo "$usage";;
---version) exec echo "$version";;
+--help) printf '%s\n' "$usage" || exit 1; exit;;
+--version) printf '%s\n' "$version" || exit 1; exit;;
esac
exec gzip -cd "$@"
Report bugs to <bug-gzip@gnu.org>."
-st=0
case $1 in
---help) echo "$usage" || st=2; exit $st;;
---version) echo "$version" || st=2; exit $st;;
+--help) printf '%s\n' "$usage" || exit 2; exit;;
+--version) printf '%s\n' "$version" || exit 2; exit;;
esac
exec zdiff --__cmp "$@"
while :; do
case $1 in
- --h*) printf '%s\n' "$usage" || exit 2; exit;;
- --v*) echo "$version" || exit 2; exit;;
+ --h*) printf '%s\n' "$usage" || exit 2; exit;;
+ --v*) printf '%s\n' "$version" || exit 2; exit;;
--) shift; break;;
-*\'*) cmp="$cmp '"`printf '%sX\n' "$1" | sed "$escape"`;;
-?*) cmp="$cmp '$1'";;
(gzip -cd -- "$1" 4>&-; echo $? >&4) 3>&- | eval "$cmp" - '"$FILE"' >&3
);;
*)
- echo >&2 "$0: $1: unknown compressed file extension"
+ printf >&2 '%s\n' "$0: $1: unknown compressed file extension"
exit 2;;
esac
elif test $# -eq 2; then
esac;;
esac
else
- echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
+ printf >&2 '%s\n' \
+ "$0: invalid number of operands; try \`$0 --help' for help"
exit 2
fi
Report bugs to <bug-gzip@gnu.org>."
if test $# = 0; then
- echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
+ printf >&2 '%s\n' "$0: invalid number of operands; try \`$0 --help' for help"
exit 1
fi
res=0
for i do
case "$i" in
- --h*) exec echo "$usage";;
- --v*) exec echo "$version";;
+ --h*) printf '%s\n' "$usage" ; exit;;
+ --v*) printf '%s\n' "$version"; exit;;
*[-.]z | *[-.]gz | *.t[ag]z) continue;;
esac
if test ! -f "$i" ; then
- echo zforce: $i not a file
+ printf '%s\n' "zforce: $i not a file"
res=1
continue
fi
new="$i.gz"
if mv "$i" "$new"; then
- echo $i -- replaced with $new
+ printf '%s\n' "$i -- replaced with $new"
else
res=$?
fi
fi
have_pat=1;;
(--h | --he | --hel | --help)
- echo "$usage" || exit 2
+ printf '%s\n' "$usage" || exit 2
exit;;
(-H | --wi | --wit | --with | --with- | --with-f | --with-fi \
| --with-fil | --with-file | --with-filen | --with-filena | --with-filenam \
(-h | --no-f*)
no_filename=1;;
(-V | --v | --ve | --ver | --vers | --versi | --versio | --version)
- echo "$version" || exit 2
+ printf '%s\n' "$version" || exit 2
exit;;
esac
Report bugs to <bug-gzip@gnu.org>."
case $1 in
---help) exec echo "$usage";;
---version) exec echo "$version";;
+--help) printf '%s\n' "$usage" ; exit;;
+--version) printf '%s\n' "$version"; exit;;
esac
if test "${LESSMETACHARS+set}" != set; then
Report bugs to <bug-gzip@gnu.org>."
case $1 in
- --h*) exec printf '%s\n' "$usage";;
- --v*) exec printf '%s\n' "$version";;
+ --h*) printf '%s\n' "$usage" ; exit;;
+ --v*) printf '%s\n' "$version"; exit;;
--) shift;;
-?*) printf >&2 '%s\n' "$0: $1: unknown option; try '$0 --help' for help"
exit 1;;
for arg
do
case "$arg" in
- --help) exec echo "$usage";;
- --version) exec echo "$version";;
+ --help) printf '%s\n' "$usage" ; exit;;
+ --version) printf '%s\n' "$version"; exit;;
-*) opt="$opt $arg"; shift;;
*) break;;
esac
exit 1
fi
-opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
+opt=`printf '%s\n' "$opt" | sed -e 's/ //g' -e 's/-//g'`
case "$opt" in
- *t*) check=1; opt=`echo "$opt" | sed 's/t//g'`
+ *t*) check=1; opt=`printf '%s\n' "$opt" | sed 's/t//g'`
esac
case "$opt" in
- *K*) keep=1; check=1; opt=`echo "$opt" | sed 's/K//g'`
+ *K*) keep=1; check=1; opt=`printf '%s\n' "$opt" | sed 's/K//g'`
esac
case "$opt" in
- *P*) pipe=1; opt=`echo "$opt" | sed 's/P//g'`
+ *P*) pipe=1; opt=`printf '%s\n' "$opt" | sed 's/P//g'`
esac
if test -n "$opt"; then
opt="-$opt"
fi
for i do
- n=`echo "$i" | sed 's/.Z$//'`
+ n=`printf '%s\n' "$i" | sed 's/.Z$//'`
if test ! -f "$n.Z" ; then
- echo "$n.Z not found"
+ printf '%s\n' "$n.Z not found"
res=1; continue
fi
test $keep -eq 1 && old=`wc -c < "$n.Z"`
touch -r"$n.Z" -- "$n$ext" 2>/dev/null
chmod --reference="$n.Z" -- "$n$ext" 2>/dev/null
else
- echo "error while recompressing $n.Z"
+ printf '%s\n' "error while recompressing $n.Z"
res=1; continue
fi
else
if cp -p "$n.Z" "$n.$$"; then
:
else
- echo "cannot backup $n.Z"
+ printf '%s\n' "cannot backup $n.Z"
res=1; continue
fi
fi
:
else
test $check -eq 1 && mv "$n.$$" "$n.Z"
- echo "error while uncompressing $n.Z"
+ printf '%s\n' "error while uncompressing $n.Z"
res=1; continue
fi
if gzip $opt "$n"; then
else
if test $check -eq 1; then
mv "$n.$$" "$n.Z" && rm -f "$n"
- echo "error while recompressing $n"
+ printf '%s\n' "error while recompressing $n"
else
# compress $n (might be dangerous if disk full)
- echo "error while recompressing $n, left uncompressed"
+ printf '%s\n' "error while recompressing $n, left uncompressed"
fi
res=1; continue
fi
else
mv "$n.$$" "$n.Z" && rm -f "$n$ext"
fi
- echo "$n.Z smaller than $n$ext -- unchanged"
+ printf '%s\n' "$n.Z smaller than $n$ext -- unchanged"
elif test $check -eq 1; then
if gzip -t "$n$ext" ; then
else
test $pipe -eq 0 && mv "$n.$$" "$n.Z"
rm -f "$n$ext"
- echo "error while testing $n$ext, $n.Z unchanged"
+ printf '%s\n' "error while testing $n$ext, $n.Z unchanged"
res=1; continue
fi
elif test $pipe -eq 1; then