the first line in the shell script should be the interpreter location to be used
#!/bin/bash ----> this interpreter is taken to execute the file
if this is not there the shell which launched this will be taken.
echo –n no new line
eco –e take special
Double Quotes | does interpolation , substitutes with var value |
Single Quotes | no manipulation directly prints |
Back Quotes | executes a command and gives us output. |
Special variables in shell
program to print
- program name
- number of paramerters
- all arguments
echo "program name is $0"
echo "argument one dollar 1 $1"
echo "argument two dollar two $2"
echo "argument three Dollar three $3"
IFS=":"
echo "all args $@ "
echo "all args with delimiter $* "
If in Shell Script:
if test $x –lt $y
OR
if [$x –lt $y]
Check the file properties
root@v11> if [ -e shell.sh ]; then echo yes ; else echo no; fi
yes
root@v11> if [ -f shell.sh ]; then echo yes ; else echo no; fi
yes
root@v11> if [ -d shell.sh ]; then echo yes ; else echo no; fi
no
root@v11> if [ -L shell.sh ]; then echo yes ; else echo no; fi
no
root@v11> if [ -r shell.sh ]; then echo yes ; else echo no; fi
yes
Case in Shell Script:
case $1 in
a) echo "this is a";;
b) echo "this is b";;
c) echo "this is c";;
*) echo "this is default";;
esac
While in Shell Script:
num=0;
while [ $num -lt $# ]
do
echo $num
num=$[num+1]
done
Until in Shell Script:
For in Shell Script:to print all the command line arguments passed using for
for i in $@
do
echo $i
done
Handling Signals
trap "echo trapped; exit;" SIGINT
while [ 1 ]
do
echo "hi"
done
No comments:
Post a Comment