[Novalug] Shell Puzzle Challenge
jbholland at gmail.com
Fri Mar 16 18:49:13 EDT 2012
On 3/16/12 7:45 PM, James Ewing Cottrell 3rd wrote:
> Well, it certainly works, but you used an external command (tr) when
> you didn't have to.
> Of course you could have done this:
what is this?
> set $PATH
doesn't this set PATH to nothing?
> for entry # in * is assumed
how does this reference the PATH var?
> what you said
> I had also asked for a shell function rather than a script, which
> would mean you'd have to save an restore IFS:
> Also...no reason to quote the colon on tr.
> P.S. The optimization I was thinking about cannot be applied to your case.
what is the optimization? Or has that not been revealed yet?
> On 3/16/2012 5:18 PM, John Holland wrote:
>> I'll take the bait:
>> for entry in `echo $PATH | tr ":" "\n"`
>> if [ $entry = $1 ]
>> exit 0
>> exit 1
>> On 3/16/12 6:00 PM, James Ewing Cottrell 3rd wrote:
>> > Since there seems to be an interest in Shell Scripting right now, I'd
>> > like to issue the following challenge:
>> > Write a shell function called "ispath" which returns true if its
>> > argument is part of $PATH, otherwise false
>> > In other words, I want to use it like this:
>> > export PATH=/sbin:/usr/sbin:/bin:/usr/bin
>> > if ispath /bin
>> > then echo YES
>> > else echo NO
>> > fi
>> > -> YES
>> > if ispath /i/love/selinux
>> > then echo Hi, I am Peter
>> > else echo Yo, I be JIM
>> > fi
>> > -> echo Yo, I be JIM
>> > I'll tell you right now that there is a trick to it that makes it
>> > simpler. This trick is not only useful in this case, but is useful to
>> > programming in general.
>> > JIM
>> > P.S. You can use "return 0" to return a true result and "return 1" to
>> > return false
>> > _______________________________________________
>> > Novalug mailing list
>> > Novalug at calypso.tux.org
>> > http://calypso.tux.org/mailman/listinfo/novalug
>> Novalug mailing list
>> Novalug at calypso.tux.org
> Novalug mailing list
> Novalug at calypso.tux.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Novalug