This site is about programming(mostly) things I either do or am learning.
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.
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:
1 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 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.
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