BASH tips

01 Dec 2014 | |

"Why are you bashing your head against the wall? Because it feels so good when I stop."


If you are like most of us in the USA and grew up with Bill Gates/Microsoft/Windows, coming to the UNIX world is quite a change. My first exposure was my MAC. But after awhile, you realize its just better.

I even have linux set up on my laptop, and switch distros often just to marvel in the creativity and designs.

Anyway…this section is a repository of BASH stuff I have picked up which can be frustrating at times.

[] && || source

Often times in bash scripts it is quite common to see these all over the place…how do you read them?

In Bash the [ is a builtin command as well as an executable. [[ is just a keyword to Bash. Very similar to what we see in ruby, where they are methods.

At terminal you can do the following to see it:

type -a [
What about && and   which you see quite often? I used to think they were “and” and “or” but not exactly.

They ARE operators with the following rules:

The right side of && will only be evaluated if the exit status of the left side is zero. || is the opposite: it will evaluate the right side only if the left side exit status is nonzero. You can consider [ … ] to be a program with a return value. If the test inside evaluates to true, it returns zero; it returns nonzero otherwise.

They are often put together to basically make logic in bash files: From the bash man page test expr [ expr ] Return a status of 0 or 1 depending on the evaluation of the conditional expression expr. Each operator and operand must be a separate argument. Expressions are composed of the primaries described above under CONDITIONAL EXPRESSIONS. test does not accept any options, nor does it accept and ignore an argument of – as signifying the end of options.

source command

. (source or dot operator meaning you can use a . instead of the word source!)

Read and execute commands from the filename argument in the current shell context.

double dash ‘–’

In bash the ‘–’ double dash is used to signify the END of command options which are normally preceded by ‘-‘ a single dash


‘export’ creates an environmental variable which can be inherited by child processes

comments powered by Disqus

Older · View Archive (21)

Test post

The standard Lorem Ipsum passage, used since the 1500s

“Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.”


Lorem ipsum

Lorem markdownum potiunda maerenti vernum tantaeque arbore superstes vulnera, loqui voce inque auro, sed. Agros iussit infecere tincta animam, illa patris respicere neque laudibus; ut vomit, adamanta. Pari nec; hanc ordo illud naris terraeque, ferox dolendi.