Monday, November 21, 2016

Material



http://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_01.html


When to use symbols: {}, [], $, @, ., >, >>,"",'',


Comments in Shell

Anything that follows the pound sign is ignored. If the pound sign starts at the beginning of a line, then entire line is ignored. If a pound sign is encountered in the middle of a line, only the information to the right of the pound sign is ignored.


Positional Parameters in shell script

In positional Parameter are variables that contain the contents of the command line.  These variables are $0 to $9. The script itself is stored in $0, first parameter is $1 and so on. This is how parameters are passed to the script.

$ sh <scirpt_name>.sh parameter1 parameter2 ....

Ex:
echo "the script: $0 is passed with first parameter value: $1 and second parameter: $2"

dlyelgg@lgpbd1100[(IPC2-Gold-EDGE) ~/srik]$ sh Positional_Parameters.sh 1 2

O/P:
the script: Positional_Parameters.sh is passed with first parameter value: 1 and second parameter: 2


-----------------------

To access all parameters in positional parameters use $@

Ex:
for para in $@
do
echo "The parameters passed to the script: $0 are $para"
done

dlyelgg@lgpbd1100[(IPC2-Gold-EDGE) ~/srik]$ sh Accessing_PossitionalParameters.sh 1 2 3
'ccessing_PossitionalParameters.sh: line 2: syntax error near unexpected token `do
'ccessing_PossitionalParameters.sh: line 2: `do

Operators in Shell



Arithmetic operators:
str1 -le str2   --less than or equal
str1 -ge str2 --- greater than or equal
str1 -ne str2 --- not equal
str1 -lt str2   --less than
str1 -gt str2 --- greater than
str1 -eq str2 --- equal to



#!/bin/bash
var1=1
var2=2
echo $var1
if ["${var1}"=="${var2}"];then
echo "Var1 has valid value"
fi
#if [$var1 -eq $var2]
#then
#echo "variable values are same"
#fi


dlyelgg@lgpbd1070[(IPC2-Gold-EDGE) ~/srik]$ sh Arithmetic_operators.sh
1
Arithmetic_operators.sh: line 12: syntax error: unexpected end of file