-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell-scripting.odt
More file actions
100 lines (71 loc) · 2.34 KB
/
shell-scripting.odt
File metadata and controls
100 lines (71 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
Running a file
================
using sh command
1. We can directly run the file
sh example.sh
sh example
2. using ./
* For that we need to be in the directory where the file resides.
* set executable permisiion using
chmod +x file name.
* File can be run as follows,
./example.sh
./basic
Exit Status
=============
Whenever a command is run its success status can be determined using its exit status value
0 -------> Success
1 -------> Failure
eg : mv demo.txt test.txt
echo $?
Display 0 if the file is already there
Otherwise iyt would display 1
Variables
===============
1. System Varibales or Environment variables
Not supposed to change without any valid reason
printenv ---This command will display all Env variables
2. USer Defined Variables
3. Multi line comments
<<"COMMENT"
This long comment text includes ${parameter:=expansion}
`command substitution` and $((arithmetic++ + --expansion)).
COMMENT
4. Expressions
s=`expr 1 + 3`
echo $s
( Back quotes NOT single quotes, and also spaces on either sides of + is important)
But the preferable way to do this :
t=$(( 1+3 )) /* here spaces are not at all important , if we want we can give them* /
echo $t
5 Quotes
6. If -else
if [ expression ]
then
Statement(s) to be executed if expression is true
else
Statement(s) to be executed if expression is not true
fi
The indentation is very important.
The semicolon is needed only when the end of line is missing:
if [ "a" == "a" ] ; then echo "true" ; fi
Without semicolons, you get Syntax error.
7. Multi level if-else
if condition
then
condition is zero (true - 0)
execute all commands up to elif statement
elif condition1
then
condition1 is zero (true - 0)
execute all commands up to elif statement
elif condition2
then
condition2 is zero (true - 0)
execute all commands up to elif statement
else
None of the above condtion,condtion1,condtion2 are true (i.e.
all of the above nonzero or false)
execute all commands up to fi
fi