<<< Date Index >>>     <<< Thread Index >>>

Re: when using `which` send errors to /dev/null



On 2007-05-24 08:24:32 +0200, Ralf Wildenhues wrote:
> * Cameron Simpson wrote on Thu, May 24, 2007 at 01:31:31AM CEST:
> > On 23May2007 13:33, David Champion <dgc@xxxxxxxxxxxx> wrote:
> > 
> > | { 
> > |     echo $PATH | tr : '\012' | while read dir; do
> > 
> > This is more robustly written:
> > 
> >   printf "%s\n" "$PATH" | tr : '\012' | while read -r dir; do

IIRC, printf doesn't exist on some old (non-POSIX) platforms.

> And even more robustly (and faster!) written like this:
> 
>   save_IFS=$IFS
>   IFS=:
>   for dir in $PATH; do
>     IFS=$save_IFS
>     ...
>   done
>   IFS=$save_IFS

The PATH separator is not necessarily ":". The configure script does
the following (from autoconf) to get the PATH separator:

# The user is always right.
if test "${PATH_SEPARATOR+set}" != set; then
  echo "#! /bin/sh" >conf$$.sh
  echo  "exit 0"   >>conf$$.sh
  chmod +x conf$$.sh
  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
    PATH_SEPARATOR=';'
  else
    PATH_SEPARATOR=:
  fi
  rm -f conf$$.sh
fi

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)