Chris's Wiki :: blog/programming/BourneShellLists Commentshttps://utcc.utoronto.ca/~cks/space/blog/programming/BourneShellLists?atomcommentsDWiki2006-08-15T02:17:39ZRecent comments in Chris's Wiki :: blog/programming/BourneShellLists.By Chris Siebenmann on /blog/programming/BourneShellListstag:CSpace:blog/programming/BourneShellLists:56db188c70886f80ab500dbc90e878e6b36255e8Chris Siebenmann<div class="wikitext"><p>There's a number of workarounds for splitting up <code>$PATH</code> et al, but
they're workarounds. I maintain that you shouldn't need workarounds
for this sort of thing.</p>
<p>The <a href="http://www.star.le.ac.uk/~tjg/rc/">Unix rc</a> solution is to have
a new <code>$path</code> variable that's a real list and maintain <code>$PATH</code> in
sync with it for backwards compatibility, and I think this is the right
way to go. (I believe Plan 9 and thus the original version of <code>rc</code> just
did away with <code>$PATH</code> entirely.)</p>
<p>(The less said about csh's 'we'll pretend we have real lists, but we
actually don't' approach, the better. But then csh is very good at
snatching defeat from the jaws of a potential victory.)</p>
</div>2006-08-15T02:17:39ZBy Dan.Astoorian on /blog/programming/BourneShellListstag:CSpace:blog/programming/BourneShellLists:9a8c80f00887960d2d18bc85a59ae931304daa6aDan.Astoorian<div class="wikitext"><blockquote><p>In a sane shell you would be able to write 'for d in $PATH'; in the Bourne shell, you can't.)</p>
</blockquote>
<p>Actually, you can; you just have to set the shell variable <code>IFS</code> appropriately first, which may have other surprising and unintended effects. Many scripters cope with this by saving <code>IFS</code> in another variable and restoring it when done parsing; others find it more elegant to use a subshell, <em>e.g.</em>:</p>
<pre>
( IFS=:; for d in $PATH; do ls -ld $d; done )
</pre>
<p>Perhaps not the most elegant construct, but csh's solution to the same problem (maintaining a space-delimited shell variable in sync with the colon-separated environment variable) is not an aesthetic improvement, if you ask me.</p>
<p>--Dan Astoorian</p>
</div>2006-08-14T21:32:42Z