5 ms·
Bash Bracket Cheat Sheet (By Julia Evans)
- jakeva 6y agoI have always found bash syntax super confusing. I always enjoy Julia's take on different topics, but I have to confess I was hoping for a little more here than "[[ is bash syntax. it’s more powerful than ["
- chubot 6y agoSome more info here: [ Is a Builtin, But [[ Is Part of the Language http://www.oilshell.org/blog/2016/10/12.html http://www.oilshell.org/blog/2016/10/12.html There are lots of subtleties about it, which I don't really recommend learning. Oil fixes a bunch of these problems: http://www.oilshell.org/blog/2020/01/simplest-explanation.html http://www.oilshell.org/blog/2020/01/simplest-explanation.ht... But if you really want to know: * It also has == which does NOT mean equality. It means fnmatch (glob) the right-hand side. * Similarly, it has =~ to match a regex on the RHS. However you should avoid using a literal regex, and use a var $pat instead, because bash's lexing/escaping/quoting of the pattern is busted, and it even says so in the bash manual. Summary: [ "$a" == "$b" ] # string equality [ "$a" = "$b" ] # string equality [[ $a == $b ]] # fnmatch [[ $a = $b ]] # fnmatch [[ $a =~ $b ]] # regex match [[ $a -eq $b ]] # numeric equality (( a == b )) # numeric equality (( a = b )) # numeric assignment! Again, if you don't want to remember all that, try Oil instead :) Tell me what happens -- it's still open to feedback and change. It has dynamic types and operators like Python or JS. There's only one expression language, which replaces all these inconsistent constructs.
- paledot 6y agoI mean, yes, but this looks more like a table of contents. I imagine there are a couple of pages later in the zine devoted to [ vs. [[, since that's at the heart of bash programming.
- neduma 6y agoPanel 11 is one of my favorite interview question.
- m463 6y agoSeems like random specialized knowledge rather than a measure of employability. In other words, could a competent engineer write shell scripts well yet not have encountered that specific feature?
- tzs 6y ago"<(cmd)" and ">(cmd)" would be nice to add.