-
Notifications
You must be signed in to change notification settings - Fork 0
/
helloscript.sh
155 lines (116 loc) · 2.43 KB
/
helloscript.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
# ! /bin/bash
cars=('BMW' 'Mercedes' 'Toyota')
unset car[2]
cars[2] = 'Mercedes'
echo "${!cars[@]}"
echo "${#cars[@]}"
______________________________
function funcname() {
echo $1 $2 $3 $4
}
funcname hi this is sanket
______________________________
mkdir -p Directory2
echo "Enter file name which you want to read"
read filename
touch $filename
if [ -d "$dir" ]
then
echo "$dir exists"
else
echo "$dir doesnt exists"
fi
if [ -f "$filename" ]
then
echo "enter text which you want to append"
read fileText
echo "$fileText" >> $filename
else
echo "$filename doesnt exists"
fi
if [ -f "$filename" ]
then
while IFS= read -r line
do
echo "$line"
done < $filename
else
echo "$filename doesnt exists"
fi
if [ -f "$filename" ]
then
rm $filename
echo "file has been deleted successfully"
else
echo "$filename doesnt exists"
fi
------------------------------
Sending email Via script
ssmtp sanketkankariya8820@gmail.com
-------------------------------------
CURL
url="https://images.pexels.com/photos/704977/pexels-photo-704977.jpeg"
curl -I ${url} >linux.txt
-------------------------------------
select car in BMW Mercedes Tesla Rover Toyota
do
# echo "$car"
case $car in
BMW)
echo "BMW Selected"
Mercedes)
echo "Mercedes Selected"
*)
echo "error"
esac
done
---------------------------------------
echo "press any key"
while [ true ]
do
read -t 3 -n 1
if [ $? = 0 ]
then
echo "you have terminated the loop"
exit;
else
echo "Waiting"
fi
done
------------------------------------------------
GREP
echo "Enter file name in which you want to Search"
read filename
if [ -f $filename ]
then
echo "Enter the word you want to Search in the file"
read word
grep -i -n $word $filename
grep -i -c $word $filename
grep -i -v $word $filename
else
echo "File doesnt exists"
fi
------------------------------------------------
AWK
echo "Enter file name in which you want to Search"
read filename
if [ -f $filename ]
then
# awk '{print}' $filename
# awk '/Windows/ {print}' $filename
awk '/Windows/ {print $4,$2}' $filename
else
echo "File doesnt exists"
fi
--------------------------------------------
SED
echo "Enter file name in which you want to Search"
read filename
if [ -f $filename ]
then
# sed 's/i/I/' $filename
sed -i 's/i/I/g' $filename > newfile.txt
else
echo "File doesnt exists"
fi