Shell Scripting

Sunday, February 1, 2015

Shell Scripting: Part 1

1. UNIX command should be in back cotes (`) in echo statement, otherwise it treats as a text.

bash-3.2$ echo "todays date is :`date`"
o/p-todays date is :Sun Feb  1 09:36:33 EST 2015
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2. "Constant": It is a fixed value it doesn’t change during execution of the program.

$readonly a
When the variable is made readonly the shell doesn’t allow you to change their values.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

3. Shell script for doing simple arithmetic operations

Note1: Expr is a command to evaluating arithmatic expressions.But expr is capable of carrying out only integer arthematic.

Note2: *_ ? [] ---wild chard characters we will use “\”. And there be no space b/w this wild card character "\" and arithmetic operator as per below product expr ex: "expr $a \* $b"

Note3: Also there should be no space b/w variable and expression. There should be space b/w variables used in arithmetic operations. for ex: $a / $b

echo "enter 2 numbers"
read a b
c=`expr $a + $b`
echo "addition is $c"
e=`expr $a \* $b`
echo "product is $e"
f=`expr $a / $b `
echo "division is $f"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

4. Relational operators: -gt (>),- lt(<) ,- ge (>=),-le (<=),-eq(=),-ne(!=)

5.  Below are some variables which will help in scripting

$$ is the PID of the current process.

$? is the return code of the last executed command.

$# is the number of arguments in $*

$* is the list of arguments passed to the current process

No comments:

Post a Comment