-
Notifications
You must be signed in to change notification settings - Fork 0
/
testfile.sh
168 lines (131 loc) · 2.31 KB
/
testfile.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# ls /some/random/location 2> /dev/null
# echo $?
# HOST=$1
# ping -c 1 $HOST 1> /dev/null
# if [[ $? -eq 0 ]]; then
# echo "HOST=$HOST"
# echo "Command Successfull.."
# else
# echo "Command failed miserably.."
# fi
# checking with && and || operator
# ping -c 1 $HOST 1>/dev/null && echo "Command Executed Successfully"
# ping -c 1 $HOST 1>/dev/null || echo "Executing anyways"
# ping -c 1 $HOST 1>/dev/null 2>/dev/null
# RETURNCODE=$?
# if [[ $RETURNCODE -ne "0" ]];then
# echo "Command failed .."
# exit 69
# fi
# exit 0
# function hello()
# {
# echo "jfkasjkf"
# }
# hello1 ()
# {
# echo "abc"
# }
# hello
# hello1
# function run()
# {
# echo "The time is : $(date +%r)"
# }
# function hello()
# {
# echo "hello"
# run
# }
# hello
# echo $@
# the usage of the local keyword
# function testfunc()
# {
# local variable_local="waduhekk"
# # checking for the return code of the function
# ls /some/random/location 2>/dev/null
# return 0
# }
# variable_local="maduhekk"
# testfunc
# echo $?
# echo $variable_local
# testing some previous knowledge
# function backup()
# {
# if [[ -f $1 ]];then
# local BACK="/tmp/$(basename $1).$(date +%T).$$"
# echo "[+] Backing up $1 to $BACK"
# cp $1 $BACK
# fi
# }
# # backup $1
# if [[ "$?" -eq "0" ]];then
# backup $1
# fi
# function myfunc()
# {
# local SECRET=0
# read -p "Enter the secret number: " SECRET
# if [[ $SECRET -eq 42 ]];then
# if [[ -f /tmp/win.txt ]];then
# echo 1>/dev/null
# else
# echo "Youwin" > /tmp/win.txt
# fi
# cat /tmp/win.txt
# return 0
# else
# return 1
# fi
# }
# Num=0
# while [[ $Num -ne 10 ]]
# do
# myfunc
# if [[ $? -eq 0 ]];then
# break
# fi
# ((Num++))
# done
# for i in $(ls); do
# echo $i
# done
# FIRST=$1
# echo $FIRST
# shift
# echo $@
# HOST=$1
# while ping -c 1 $HOST >/dev/null
# do
# echo "Server up !!!"
# sleep 3
# done
# echo "Server Down , exiting !!"
# exit 1
# reading content line-by-line from a file
LINE_NUM=1
# while read LINE
# do
# echo "$LINE_NUM: $LINE"
# ((LINE_NUM++))
# done < /etc/fstab
# set -x
# read -p "Enter num: " NUM
# while [[ "$NUM" -le "5" ]]
# do
# echo $NUM
# ((NUM++))
# done
# set +x
# set -e
# ls /nonexistent/file
# set +e
# echo hellworld
# set -v
FILE="/etc/passwd"
echo $FILE
# set +v
# all the code above will be updated regularly