Saturday, November 12, 2011

Don't use backticks in bash!

No, don't, it's very ugly. And I don't know how I would read something like this:
gniourf@somewhere:~$ echo `echo `echo hello``
You know, in more modern bash, we use $(...) instead of `...`. So what do you think of the previous line? Which of the following two possibilities is it?
gniourf@somewhere:~$ echo $(echo $(echo hello)) # Possibility 1
gniourf@somewhere:~$ echo $(echo )echo hello$() # Possibility 2
You'll figure it out by yourself, but you probably understand that the $(...) is more robust, since it doesn't leave any ambiguity whatsoever: nestings are neat!

Cheers!

No comments:

Post a Comment