Friday, June 27, 2014

shell script leanring - note1

Because computers only understand the language of 0 and 1, which is called binary language.

What is Shell?
So Shell is a language interpreter that executes commands read from the standard input device (keyboard) or from a file. It reads your command, interpret and transfer your command to kernal in Linux.

What is Kernel?
Kernel decides who will use this resource, for how long and when. It runs your command or programs (or execute binary files).

$ is important in Bash shell.
Example: $HOME, $n. Only $ + variable can work.

User defined variables
Example: n=10
                  atring=hello

Rules for naming variables:
1. Variable name must begin with Alphanumeric character or underscore character (_), followed by one or more Alphanumeric character.
2. DON'T put spaces on either side of the equal sign when assigning value to variable. THIS IS IMPORTANT since you can easily forget it.
3. Variables are case-sensitive, e.g. N /=n
4.  DO NOT use *, or ?

Math operation in Shell
 1. expr op1 math-operator op2## WATCH THE SPACE BETWEEN OPERATOR.
2. echo `expr 5 + 6` # will show 11. Watch the punctuation is not quote.

Double quote, single quote and back quote.
echo "today is date" # output: today is date
echo "today is `date`" #output: today is Fri Jun 27 13:40:19 PDT 2014
echo 'today is `date`' #output: today is `date`
 

No comments:

Post a Comment