BASH tips

01 Dec 2014 | |

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

BASH Tips

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:

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 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

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

comments powered by Disqus(comments off)

Newer · View Archive (32)

The Song Remains the Same

"When you get old in life...things get taken from you. That's part of life. But you only learn that when you start losing stuff." Al Pacino(On Any Given Sunday) </br>

Goodbye iSeries

The date of this blog is Christmas Day. I think on Christmas day I was doing the things most Dad’s do, trying to manage the Christmas present wrapping paper trash, and at the same time reliving christmas past thru the christmas present with my family. At this age I am past presents, at least the physical ones. Been there done that.

I have reached a decision point in my working life. The type I development I have done for years is fading away. And I realized that in order to keep doing what I really enjoy as a job I need to re-tool. I decided to move to Ruby and Ruby on Rails and NodeJS/Javascript. I started Tealeaf Academy and I am not looking back. My friends say “hey…Christmas is for kids!”..but I say…everyone enjoys Christmas. Wish me luck.

1
2
3
4
def say_hello_rails
puts "Hi there!"
puts "Every language seems to have a puts."
end