Saturday, 29 April 2017

Learning Linux - Mastering the Command Line: Comparisons in Bash

Learning Linux - Mastering the Command Line: Comparisons in Bash

At some point in your Linux journey you'll start creating shell scripts, and at some point in that process you'll find it necessary to perform logical comparisons. Is this bigger than that? Is that the same as this? And so on. Here's a tutorial to get you started.

#Linux #CommandLine #Sysadmin
http://www.linuxtechi.com/compare-numbers-strings-files-in-bash-script/

3 comments:

  1. That article has bad advice. For one thing, you should always prefer [[ over [ because the latter has some strange corner cases for backwards-compatibility reasons. For another, you should use (( where possible for numeric tests. In general, I recommend the Google Shell Style Guide for scripting wisdom.
    google.github.io - google.github.io/styleguide/shell.xml

    ReplyDelete
  2. Adrian Colley if by "strange corner cases" you mean POSIX compliance, then yes. But that only happens because you are incorrectly using == vs. =
    To say the article is giving bad advice is not accurate. It's giving strictly correct advice that is contrary to your personal preference.
    Using commands in a POSIX compliant way whenever possible is in fact good advice as it makes your scripts more portable.

    ReplyDelete
  3. Also, as much as I like Google I don't consider them the authority on bash (or Linux for that matter).
    The Linux Documentation Project is a better reference source.


    tldp.org - Bash Guide for Beginners

    ReplyDelete