• bash,  Mac OS X

    Bash: if, then, else, and expressions

    One of the most important skills in any language is to know how a basic if then statement works. You set a variable, you say if that variable matches a given pattern (or doesn’t) then do something or else do something different. If/then/else. Other than that, it’s just syntax, and the annoyance of figuring out the operators and syntax.  So let’s go through the below script (which checks a Mac to see if grayscale is enabled in Universal Access), line-by-line: Line 1: we’re first going to create a variable called grayscale. We’ll fill it with a 0 or 1, the output of a simple “defaults read com.apple.universalaccess grayscale” command If that grayscale…