[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 808ercise: Shell Golf
On Fri, 2003-04-18 at 23:53, mike808@users.sourceforge.net wrote:
> Bzzzzzzzzzt.
:(
> Weiqi tried and failed (sorry about the line wrap):
> > echo "for x in *;do file \$x|grep -q script&&[ -x \$x ]&&grep -H \
> > that\ pays \$x;done"|sh
> >
> > 88!
>
> > On Fri, 2003-04-18 at 15:15, mike808@users.sourceforge.net wrote:
> > > A solution is disqualified if a test case can demonstrate any of:
> > > 1. The command produces any output other than the matching grep output.
> > > 2. Performs grep searches of any file other than script files.
> > > 3. Does not perform a grep search of all script files.
> > > 4. Does not locate an instance of the phrase 'that pays' in a script file.
>
> Your solution will fail for a binary executable containing the phrase that
> just happens to be named 'this is not a script'.(#2)
Using the -b switch on the file command will fix this. Three more
characters.
> Your solution may also fail for files containing spaces in their names.(#1,#2)
Quoting all the $x's correctly will cost me 12 characters. We should
ban file names that contain spaces!
> Very close, though.
Now that I think about it, I need to handle hidden files. And other
808ish stuff that I don't know that I don't know.
> After two more worthy attempts, I'll post my solution.
I give up.
--
Weiqi Gao
weiqigao@networkusa.net
-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.