Chris's Wiki :: blog/unix/FilteringPATHWithBuiltins Commentshttps://utcc.utoronto.ca/~cks/space/blog/unix/FilteringPATHWithBuiltins?atomcommentsDWiki2020-02-10T00:27:30ZRecent comments in Chris's Wiki :: blog/unix/FilteringPATHWithBuiltins.By Aristotle Pagaltzis on /blog/unix/FilteringPATHWithBuiltinstag:CSpace:blog/unix/FilteringPATHWithBuiltins:d9b34cf68ec0c4606f81aa4a410b09e7edb55785Aristotle Pagaltzishttp://plasmasturm.org/<div class="wikitext"><p>This particular example happens to port essentially identically to Bourne shell.</p>
<pre>
PATH=` IFS=: ; unset tpath
for pe in $candidates
do cd $pe &> /dev/null && tpath=${tpath+$tpath:}$pe ; done
echo "$tpath" `
</pre>
<p>No need to pay attention to trailing colons or the like, either.</p>
</div>2020-02-10T00:27:30ZBy wime12 on /blog/unix/FilteringPATHWithBuiltinstag:CSpace:blog/unix/FilteringPATHWithBuiltins:70b057c15b35eb69a99d8216dcec7f4f4eaec01bwime12<div class="wikitext"><p>Bourne shell user here. Thanks for wetting my appetite. How about this Bourne shell version?</p>
<pre>
LIST="/usr/bin:/opt/bin:/usr/local/bin:"
</pre>
<pre>
while [ -n "$LIST" ]
do
CAR="${LIST%%:*}"
LIST="${LIST#*:}"
cd "$CAR" 2>/dev/null && TPATH="$TPATH:$CAR"
done
TPATH="${TPATH#:}"
</pre>
<p>It preserves all whitespace. Note that the initial <code>LIST</code> has to be terminated with a colon.</p>
</div>2020-02-09T08:57:45Z