Re: (OT) path_helper [was Re: Xterm not reading dotfiles]
Re: (OT) path_helper [was Re: Xterm not reading dotfiles]
- Subject: Re: (OT) path_helper [was Re: Xterm not reading dotfiles]
- From: Peter O'Gorman <email@hidden>
- Date: Sun, 18 Nov 2007 21:33:18 -0600
Mark J. Reed wrote:
> path_helper is something of a mess. It is taking forever to process
> my admittedly-long MANPATH, due I think to the pathological nature of
> the *(*:)$p*(:*) regex. @($p:*|*:$p:*|*:$p) would seem to be a better
> choice.
>
> Also, it won't work if any of the desired path entries contain spaces.
> The loop construct it uses to read the files { for p in $(<"$f") }
> assigns p to each *word*, not each *line*. To loop through lines,
> something like this would work:
>
> exec 3<"$f"
> while IFS= read -u3 -r p; do
> ...
> done
Something like his should both be faster and more portable (although the
-u option to read is not portable). Also, even if an invalid option is
given, it still reads all the files etc first.
Undoubtedly C would be quicker, but this version removes most of the
forks which is what causes slowdowns in shell scripts.
Peter
#!/bin/sh
#
read_path_dir () {
DIR="$1"
NEWPATH="$2"
DIRD=
[ -d "$DIR".d ] && DIRD="${DIR}.d/*"
for f in "$DIR" $DIRD ; do
if [ -f "$f" ]; then
exec 5< "$f"
while read -u5 -r p; do
case ":${NEWPATH}:" in
*":${p}:"*) continue ;;
::) NEWPATH=${p} ;;
*) NEWPATH="${NEWPATH}:${p}" ;;
esac
done
exec 5<&-
fi
done
path_result=$NEWPATH
}
read_path_dir /etc/paths "$PATH"
P=${path_result}
read_path_dir /etc/manpaths "$MANPATH"
MP=${path_result}
case ${1-no},${SHELL} in
-c,*|no,*csh)
echo setenv PATH \"$P\"\;
echo setenv MANPATH \"$MP\"\;
;;
-s,*|no,*)
echo PATH=\"$P\"\; export PATH;
echo MANPATH=\"$MP\"\; export MANPATH;
;;
*)
echo "usage: path_helper [-c | -s]" 1>&2
exit 1
;;
esac
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list (email@hidden)
This email sent to email@hidden