Package: debianutils Version: 2.21 Followup-For: Bug #340219 While I'm in favour of #428189 too (you by the way forgot to mention that, if printf is moved to /bin, we need a /usr/bin/printf symlink to not break POSIX or existing scripts), there's a way to solve this issue for Korn shells, which all have a “print” builtin, which is, in contrast to “echo”, portable.
(Some Korn shells, at least pdksh and derivates, also have “whence -p” that does the same as “which” does, but without support for -a, and if the programme does not exist, n̲o̲ error message is printed, so I've not attached a patch to make use of “whence -p”.) Below patch introduces a shell function to output a one-line string, depending on ‘$KSH_VERSION’ which is set for almost all Korn shells (except maybe ksh88 which probably isn't suitable for Debian anyway). If other shells don't have a printf builtin, the issue is NOT solved for them with this patch (but would be with #428189). On the other hand, even if #428189 were to be accepted, I'd still apply this patch because it goes deeper to the root of the problem. --- /bin/which 2007-06-11 14:36:51.000000000 +0000 +++ which.new 2007-06-24 13:51:13.000000000 +0000 @@ -1,13 +1,23 @@ #! /bin/sh set -ef +if test -n "$KSH_VERSION"; then + puts() { + print -r -- "$*" + } +else + puts() { + printf '%s\n' "$*" + } +fi + ALLMATCHES=0 while getopts a whichopts do case "$whichopts" in a) ALLMATCHES=1 ;; - ?) printf "Usage: %s [-a] args\n" $0 ; exit 2 ;; + ?) puts "Usage: $0 [-a] args"; exit 2 ;; esac done shift $(($OPTIND - 1)) @@ -28,7 +38,7 @@ for PROGRAM in "$@"; do case $PROGRAM in */*) if [ -f "$PROGRAM" ] && [ -x "$PROGRAM" ]; then - printf '%s\n' "$PROGRAM" + puts "$PROGRAM" RET=0 fi ;; @@ -38,7 +48,7 @@ for PROGRAM in "$@"; do ELEMENT=. fi if [ -f "$ELEMENT/$PROGRAM" ] && [ -x "$ELEMENT/$PROGRAM" ]; then - printf '%s\n' "$ELEMENT/$PROGRAM" + puts "$ELEMENT/$PROGRAM" RET=0 [ "$ALLMATCHES" -eq 1 ] || break fi -- System Information: Debian Release: lenny/sid Architecture: kfreebsd-i386 (i686) Kernel: kFreeBSD 5.4-1-486 Locale: LANG=C, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/mksh Versions of packages debianutils depends on: ii libc0.1 2.5-10 GNU C Library: Shared libraries debianutils recommends no packages. -- no debconf information