Home > Ubuntu > Ehh, What The Hell

Ehh, What The Hell

I figure I’d join the band-wagon too, but I’ll use *readable* $() vs the absolutely unreadable-horrible-habit `.  (Yes, that is a `.  What?  You can’t tell what character that is?  Yeah, neither can I when you use it in your code!  Its a back-tick and shouldn’t be used because its unreadable!)

christer@007:~$ history | awk $({a[$2]++ } END{for(i in a){print a[i] " " i}})|sort -rn|head
96 ls
87 vim
70 cd
60 bzr
25 sudo
16 rm
14 ssh
13 grep
13 cat
11 scp

Categories: Ubuntu Tags:
  1. April 10th, 2008 at 12:59 | #1

    Actually, I’m having no problem telling what that is. You need a better font. :-)

  2. Tormod
    April 10th, 2008 at 15:06 | #2

    Erm… you got that all wrong. $() is equivalent to a pair of backticks (`). awk scripts are often enclosed in single quotes (‘) to keep the shell from substituting for instance the $’s used in the awk syntax.

  3. April 10th, 2008 at 20:55 | #3

    @Tormod – I’m familiar with awk using single-quotes as part of its normal operation, but the shell history code that I copy-pasted from the previous sites was using back-ticks, which I replaced with $().

    The reason I actually did it was that a copy-paste from the blog didn’t work as the back-ticks were improperly translated between blog and shell.

  4. Leonardo
    April 13th, 2008 at 17:00 | #4

    Personally, I have no problem telling the character apart, and since I usually edit scripts in Vim, the syntax highlighting finishes making it a non-problem.

    In fact, given I think $() clutters things up even more.
    But that’s just me. We seem to dissent, but at least we would agree that readability is an important quest :)

  5. April 15th, 2008 at 15:37 | #5

    So I agree with using $() on principle, but as far as I can tell it doesn’t actually work in this command.

  6. mlissner
    April 17th, 2008 at 01:10 | #6

    A more important thing to note is you can nest $(). You cannot nest back ticks.