-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables_part_1.sh
79 lines (65 loc) · 1.36 KB
/
variables_part_1.sh
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
#!/bin/sh
echo "my variable is $MY_VARIABLE"
MY_VARIABLE="Anand Vijay Singh"
echo $MY_VARIABLE
echo "my variable is $MY_VARIABLE"
echo "what is your user name..?"
read USERNAME
echo "hello Mr.$USERNAME"
echo "";echo "";
echo "Inbuilt variables"
echo "Number of parameters: $#"
echo "Script name: $0"
echo "first param: $1"
echo "second param: $2"
echo "All params: $@"
echo "Exit value of last run command: $?"
echo "current PID: $$"
echo "last run PID: $!"
echo ""
echo "executing expression"
myname=`whoami`
echo "my name is $myname"
echo ""
echo "inline executing expression"
echo -en "my name is `whoami` "
echo ""
echo "defaulting the value.. "
echo "defalut variable value ${myname2:- Anand Singh}"
clear
echo ""
echo "Function in shell script"
my_fun(){
user=$1;
password=$2;
shift; shift;
comment=$@;
echo "......functioning......"
echo "username: $user"
echo "password: $password"
echo "comments: $comment"
}
echo "calling function: myfun() "
my_fun Anand pass@123 you are great;
my_fun Vijay pass@456 linux is awesome;
echo "`my_fun Singh pass@789 enjoying shell scripting;`"
if [ "0" -ge "1" ]; then
echo "true "
else
echo "false "
fi
echo ""
echo "factorial function"
factorial_of(){
if [ "$1" -ge "1" ]; then
x=`expr $1 - 1`;
z=`expr $x * $1`;
echo "`factorial_of $z`"
else
echo 1
fi
}
factorial_of 5
echo ""
echo "press any key to exit..."
read