Chris's Wiki :: blog/programming/BourneListMatch Commentshttps://utcc.utoronto.ca/~cks/space/blog/programming/BourneListMatch?atomcommentsDWiki2007-11-14T05:06:27ZRecent comments in Chris's Wiki :: blog/programming/BourneListMatch.By Chris Siebenmann on /blog/programming/BourneListMatchtag:CSpace:blog/programming/BourneListMatch:36a3b1f750f124fd5c09e5c47ba00288dfccf5eeChris Siebenmann<div class="wikitext"><p>Your <code>" $wlist "</code> trick is much better than my brute force approach;
thanks, and I've switched my script over to using it. While a <code>for</code>
loop would work, I suspect it would be slower and I prefer to do
things in one pass if I can.</p>
</div>2007-11-14T05:06:27ZFrom 66.243.153.70 on /blog/programming/BourneListMatchtag:CSpace:blog/programming/BourneListMatch:540922167cabf5c15966d836732daf515e85fcd0From 66.243.153.70<div class="wikitext"><p>Or you can use</p>
<p>case " $wlist " in</p>
<pre>
*" $w "*) echo yes ;;
*) echo no ;;
</pre>
<p>esac</p>
<p>I find it much simpler to read this simpler pattern.</p>
<p>These days I tend to use '<code>(*" $w "*</code>)' i.e. with the leading '(' as it tends to make editors happier.</p>
<p>Icarus Sparry</p>
</div>2007-11-13T18:35:06ZFrom 65.172.155.230 on /blog/programming/BourneListMatchtag:CSpace:blog/programming/BourneListMatch:bf999893d5993c55e84e0a128d4c51a39b7fc81fFrom 65.172.155.230<div class="wikitext"><p>Well it doesn't abuse case, but personally I'd do the above using something like:</p>
<pre>
for i in $wlist; do
if [ "x$i" = "myword" ]; then
# ...
fi
done
</pre>
<p>...I'd assume my way was faster, but then I usually do :)</p>
</div>2007-11-13T17:17:49Z