3 ms·
I'm pretty sure this is cheating, but... #!/bin/sh grep -e "g\(()\)*('al')" $0 | sed 's/()/o/g' | sed "s/('al')/al/" exit g()('al') On its own, g()('a
by csandreasen 12y ago
I'm pretty sure this is cheating, but...
#!/bin/sh
grep -e "g\(()\)*('al')" $0 | sed 's/()/o/g' | sed "s/('al')/al/"
exit
g()('al')
On its own, g()('al') is valid but g()()('al') is a syntax error. Also, bash and sh don't have non-numeric return values, so regardless of the solution you're stuck with printing.
- eatnumber1 12y agoThis is a great incomplete solution. Can you submit a pull-request for it?
- csandreasen 12y agoJust to clarify, I think it's a non-solution because the g()('al') is never actually executed - grep does all the work. You can add as many parenthesis as you want. The "exit" is there because you'll get a syntax error if you try to execute g()()('al'). g()('al') by itself does nothing (I'm not even sure why it's not flagged as a syntax error).
- eatnumber1 12y agoThe three people who are judging this had a long discussion over this case, and basically decided that since it is in the file, it's fine. We frown on it a little because it's basically self-modifying code, but it's better than nothing for bash.
- tolmasky 12y agoI actually prefer it vs. frowning on it for the record ;)