Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

hello

73 views
ubuntu2004
1
# echo "first arg : $1"
2
# echo "second arg : $2"
3
# echo "third arg : $3"
4
5
# echo "$* without quotes"
6
# ./m1.sh $*
7
# echo "$@ without quotes"
8
# ./m1.sh $@
9
# echo "$* with quotes"
10
# ./m1.sh "$*"
11
# echo "$@ with quotes"
12
# ./m1.sh "$@"000
13
# a=5
14
# b=3
15
# c=$(($a+$b))
16
# d=`expr $a - $b`
17
# e=`expr $a \* $b`
18
# f=`expr "scale=2 ; $a / $b" | bc`
19
# echo $c $d $e $f
20
# read two numbers and perform all arithmatic operation
21
# input 3 numbers through commandline argument and perform arithmatic operation
22
# fi9nd average of 3 numbers
23
24
25
# echo "enter first number"
26
# read a
27
# echo "enter second number"
28
# read b
29
# c=`expr $a + $b`
30
# d=`expr $a - $b`
31
# e=`expr $a \* $b`
32
# f=`expr $a / $b`
33
# echo $c $d $e $f
34
35
# echo "first argument $1"
36
# echo "second argument $2"
37
# echo "third argument $3"
38
# c=`expr $1 + $2 + $3`
39
# d=`expr $1 - $2 - $3`
40
# e=`expr $1 \* $2 \* $3`
41
# f=`expr $1 / $2 / $3`
42
# g=`expr $1 % $2 % $3`
43
# echo $c $d $e $f $g
44
45
# echo "enter first number"
46
# read a
47
# echo "enter second number"
48
# read b
49
# echo "enter third number"
50
# read c
51
# d=`expr $a + $b + $c`
52
# e=`expr $d / 3`
53
# echo $e
54
55
# a=5
56
# b=3
57
# c=`echo "scale=2; $a / $b" | bc`
58
# echo "$c"
59
60
61
# there must be spaces between operators and expresions
62
#all the conditional expression should be inside square braces with spaces around them
63
# == -eq
64
# > -gt
65
# < -lt
66
# >= -ge
67
# <= -le
68
# != -ne
69
#check number is even or odd
70
#check given no. is +ve or -ve
71
# echo "enter 1st no. = "
72
# read a
73
# if [ $(($a % 2)) -eq 0 ]
74
# then
75
# echo "a is even"
76
# else
77
# echo 'odd'
78
# fi
79
#
80
# echo "enter 1st no. = "
81
# read a
82
# if [ $a gt 0 ]
83
# then
84
# echo "a is positive"
85
# if [ $a lt 0 ]
86
# echo "a is negative"
87
# else
88
# echo 'a is 0'
89
# fi
90
#find the largest of two numbers
91
#find the largest among 3 numbers.
92
#input the marks of a student in 3 subjects and calculate the division on the basis of percentage of marks.
93
94
# echo "enter num1= "
95
# read a
96
# echo "enter num2= "
97
# read b
98
# if [ $a -gt $b ]
99
# then
100
# echo "a is greater"
101
# else
102
# echo "b is greater"
103
# fi
104
105
# echo "enter 1st="
106
# read x
107
# echo "enter 2nd= "
108
# read b
109
# echo "enter 3rd= "
110
# read c
111
# if [ $x -gt $b -a $x -gt $c ]
112
# then
113
# echo "x is greater"
114
# elif [ $b -gt $x -a $b -gt $c ]
115
# then
116
# echo "b is greater"
117
# else
118
# echo "c is greater"
119
# fi
120
121
122
# echo "enter 1st="
123
# read x
124
# echo "enter 2nd= "
125
# read b
126
# echo "enter 3rd= "
127
# read c
128
# sum=`expr $x + $b + $c`
129
# avg=`echo "scale=0; $sum / 3 " | bc `
130
# if [ $avg -ge 80 ]
131
# then
132
# echo "first division"
133
# elif [ $avg -ge 65 -a $avg -lt 80 ]
134
# then
135
# echo "second division"
136
# elif [ $avg -ge 45 -a $avg -lt 65 ]
137
# then
138
# echo "third division"
139
# else
140
# echo "fail"
141
# fi
142
143
144
145
#case $var in
146
#pattern1)
147
#;;
148
#pattern2)
149
#;;
150
#*)
151
#esac
152
153
# echo "enter day number = "
154
# read a
155
# case $a in
156
# 1) echo "monday"
157
# ;;
158
# 2) echo "tuesday"
159
# ;;
160
# 3) echo "wednesday"
161
# ;;
162
# 4) echo "thursday"
163
# ;;
164
# 5) echo "friday"
165
# ;;
166
# 6)
167
# echo "saturday"
168
# ;;
169
# 7)
170
# echo "sunday"
171
# ;;
172
# *) echo "invalid"
173
# esac
174
#wap to check the given character is vowel consonant or special character using case
175
#wap to check even odd using case
176
#wap menu driven program to perform following operations-
177
#1. list of files
178
#2. todays date
179
#3. count number of lines and words in a file
180
#4.display number of command line argument passed.
181
182
# echo "enter a character : "
183
# read c
184
# case "$c" in
185
# [AEIOUaeiou]) echo "vowel"
186
# ;;
187
# [BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz]) echo "c is consonant"
188
# ;;
189
# [0123456789]) echo "it is a digit"
190
# ;;
191
# *) echo "special character"
192
# ;;
193
# esac
194
195
# echo "enter the number : "
196
# read a
197
# case $(($a % 2)) in
198
# 0) echo "even"
199
# ;;
200
# 1) echo "odd"
201
# ;;
202
# *) echo "invalid number"
203
# ;;
204
# esac
205
206
207
208
# echo "select an option"
209
# echo "1. list of files"
210
# echo "2.todays date"
211
# echo "3. no of lines and no. of words"
212
# echo "4. no of command line inputs "
213
# echo "5. exit"
214
# echo "enter your choice : "
215
# read ch
216
# case $ch in
217
# 1) ls ;;
218
# 2) date ;;
219
# 3) echo "enter file name : "
220
# read file
221
# echo "no of lines : $(wc -l $file | awk '{print $1}')"
222
# echo "no of words : $(wc -w $file | awk '{print $1}')"
223
# ;;
224
# 4) echo "no of command line input :
225
# ;;
226
# 5) exit ;;
227
# *) echo "invalid choice"
228
# ;;
229
# esac
230
231
# echo "Enter Operating System Marks:"
232
# read os
233
# echo "Enater C++ Marks:"
234
# read cpp
235
# echo "Enater Java Marks:"
236
# read java
237
# total=`expr $os + $cpp + $java`
238
# echo "Total Marks:"$total
239
# percentage=`expr $total / 3`
240
# echo "Percentage:" $percentage %
241
# if [ $percentage -ge 60 ]
242
# then
243
# echo "Class: First Class Distinction"
244
# elif [ $percentage -ge 50 ]
245
# then
246
# echo "Class: First class"
247
# elif [ $percentage -ge 40 ]
248
# then
249
# echo "Class: Second class"
250
# else
251
# echo "Class: Fail"
252
# fi
253
254
#print numbers 1 to 10
255
# print multiplication table of a given number
256
# wap to check a given number is palindrome or not
257
#wap to compute m to the power a positive integer.
258
#wap to read student name roollno and marks in the same line and then
259
#write the line to a file student.txt it than prompts you for more entries
260
261
# i=1
262
# while [ $i -le 10 ]
263
# do
264
# echo "$i"
265
# i=`expr $i + 1`
266
# done
267
268
269
# echo "enter a number"
270
# read n
271
# i=1
272
# while [ $i -le 10 ]
273
# do
274
# a=`expr $i \* $n`
275
# echo "$n * $i = $a"
276
# i=`expr $i + 1`
277
# done
278
279
# echo "enter the number"
280
# read a
281
# b=$a
282
# s=0
283
# while [ $a -gt 0 ]
284
# do
285
# r=`expr $a % 10`
286
# s=`expr $s \* 10 + $r`
287
# a=`expr $a / 10`
288
# done
289
# if [ $b -eq $s ]
290
# then
291
# echo "palindrome"
292
# else
293
# echo "not palindrome"
294
# fi
295
296
297
# echo "enter a number"
298
# read a
299
# echo "enter power"
300
# read p
301
# b=1
302
# while [ $p -gt 0 ]
303
# do
304
# b=`expr $b \* $a`
305
# p=`expr $p - 1`
306
# done
307
# echo "$b"
308
309
310
311
# echo "Enter student details (name, roll no, marks):"
312
# read input
313
#
314
# while [ "$input" != "quit" ]
315
# do
316
# echo "$input" >> student.txt
317
# echo "Student details added to file."
318
#
319
# echo "Enter 'quit' to exit or provide the next student details:"
320
# read input
321
# done
322
#
323
# echo "Program finished."
324
325
# nums="10 15 17 18 20 25"
326
# for i in $nums
327
# do
328
# n=`expr $i % 2`
329
# if [ $n -eq 0 ]
330
# then
331
# echo "$i is even"
332
# else
333
# echo "$i is odd"
334
# fi
335
# done
336
337
# search the pattern provided two cmd line argument in a file
338
# for i in $*
339
# do
340
# grep -w "$i" m1.sh || echo "pattern not found"
341
# done
342
343
344
345
346
# declare -a fruits=('Mango' 'Apple' 'Banana' 'Orange' 'watermelon')
347
# echo ${fruits[2]: 0:4}
348
# echo ${fruits[@]: 2:2}
349
# echo ${fruits[@]}
350
# echo ${fruits}
351
# echo ${fruits[2]}
352
# echo ${fruits[2]}
353
# echo ${fruits[@]}
354
# echo ${fruits[2]}
355
356
357
#input and print all the elements at the same line
358
# read -a arr
359
# for i in $arr
360
# do
361
# echo "$i"
362
# done
363
364
365
#input 10 integers in array and display max min total sum and avg of an array
366
#wap to sort an array in ascending order
367
368
# total=0
369
# echo "Enter the length of the array"
370
# read size
371
# for ((i=0; i<$size; i++))
372
# do
373
# read arr[i]
374
# done
375
# max=${arr[0]}
376
# min=${arr[0]}
377
# for i in "${arr[@]}"
378
# do
379
# if [ $i -gt $max ]
380
# then
381
# max=$i
382
# fi
383
# if [ $i -lt $min ]
384
# then
385
# min=$i
386
# fi
387
# total=`expr $total + $i`
388
# done
389
# avg=$(echo "scale=2; $total/$size" | bc )
390
# echo "average is : $avg"
391
# echo "total is : $total"
392
# echo "Maximum is : $max"
393
# echo "Minimum is : $min"
394
395
# temp=0
396
# echo "Enter the length of the array"
397
# read size
398
# for ((i=0; i<$size; i++))
399
# do
400
# read arr[i]
401
# done
402
# for ((i=0; i<$size; i++))
403
# do
404
# for ((j=i+1; j<$size; j++))
405
# do
406
# if [ ${arr[i]} -gt ${arr[j]} ]
407
# then
408
# temp=${arr[i]}
409
# arr[i]=${arr[j]}
410
# arr[j]=$temp
411
# fi
412
# done
413
# done
414
# echo "${arr[@]}"
415
416
417
418
419
# var="AaBbCcDdEeFfGg"
420
# test=`expr index "$var" d`
421
# echo $test
422
423
424
# string="www ist a string"
425
# substring="Xat"
426
# a=`expr index "$string" "$substring"`
427
# echo $a
428
429
430
filename="bash.string.txt"
431
echo ${filename##*.}
432
echo ${filename%%.*}
433