-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.sh
More file actions
84 lines (61 loc) · 1.23 KB
/
functions.sh
File metadata and controls
84 lines (61 loc) · 1.23 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
#!/usr/bin/bash
# Syntax:
# 1.
# function name_of_func ()
# {
# commands
# }
# 2.
# name_of_func()
# {
# commands
# }
function hello()
{
echo "Hello world"
}
quit()
{
exit
}
hello
## passing arguments to the function
function print ()
{
echo $1 $2
}
print am Rachana
# by default script variables are local variables
function lprint()
{
local name=$1
echo "Name is $name"
}
lprint Rachana
#local variable value doesnot change global variable value of the same name
#ternary operator
fname=basics.sh
[[ -f "$fname" ]] && return 0 || return 1
# if file exist 1 then || return 1 (return 0 not used)
# if file does not exist 0 then return 0 || return 1
# $# gives the number of arguments
#readonly variable are used only to read the data not to make changes
var=12
readonly var
echo "var=$var"
var=21 #will give an error because readonly variable value cannot be changed
echo "var=$var" #print 12 that is the previous value
#readonly function
whello()
{
echo "Good Bye All"
}
readonly -f whello # this will make a function as readonly function
whello
whello()
{
echo "Welcome" # will give error
}
whello
readonly # will give all readonly variables
readonly -f #will give all readonly functions