News for hackers. Stuff that matters.
Re:Why do long options start with two dashes? (2019) by ben0x539 on Thursday April 08, 2021 @08:11PM (#26745335)
`find` is weird anyway. The stuff after the arguments aren't really flags, they're a tiny filter language, with significant ordering and operator precedence and all that stuff. Using "normal" option syntax wouldn't make a lot of sense for it either.
Re:Why do long options start with two dashes? (2019) by chubot on Thursday April 08, 2021 @08:44PM (#26745553)
Yes exactly, find is like test a.k.a [.

    test -f foo -a -f bar -o -z foo
can be read

    isfile('foo') && isfile('bar') || emptystring('foo')
Likewise

    find . -name '*.py' -a -executable -o -printf '%P\n'
can be read

    (F.name matches '*.py') && (F is executable) || print('%P\n', F)
where F is the current node in the file system traversal.

They both respect -o as OR, ! as NOT, and ( ) for precedence, which you have to quote as \( and \).

A couple years ago, someone helped me implement a better "find" without this wonky syntax for https://www.oilshell.org/ . But it isn't done and needs some love. If anyone wants to help, feel free to join Zulip :)

I do think that "find" is more like a language than a command line tool. It's pretty powerful, e.g. I just used it to sort through 20 years of haphazard personal backups.

Re:Why do long options start with two dashes? (2019) by chubot on Friday April 09, 2021 @12:03AM (#26746572)
Related: Problems With the test Builtin: What Does -a Mean?

http://www.oilshell.org/blog/2017/08/31.html

Re:Why do long options start with two dashes? (2019) by ainar-g on Friday April 09, 2021 @03:43AM (#26747729)
Thanks for the article! How did I not see this before? Didn't know that POSIX has obsoleted -a and -o either. I guess I have some shell scripts to rewrite, heh.
Re:Why do long options start with two dashes? (2019) by ben0x539 on Friday April 09, 2021 @12:31AM (#26746742)
I feel like `jq` does the "more like a language" thing better than `find`, but possibly its just a product of its time.
Re:Why do long options start with two dashes? (2019) by chubot on Friday April 09, 2021 @02:10AM (#26747208)
Well the thing find and test have in common is that they lack a lexer! They abuse the argv array for tokens instead. I might call it the "I'm too lazy to write a lexer" pattern :)

jq has a lexer and hence a "real" syntax, but so does awk, which is maybe 30 years older. But yes jq is a surprisingly big and rich language, maybe bigger than awk:

https://stedolan.github.io/jq/manual/