forked from vilasvarghese/devops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathif-statement.sh
More file actions
101 lines (69 loc) · 1.67 KB
/
if-statement.sh
File metadata and controls
101 lines (69 loc) · 1.67 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
#Purpose: If statement example
#Version:1.0
#Created Date: Sat Feb 12 23:41:50 IST 2021
#Modified Date:
#Author: Vilas Varghese
# START #
echo -e "Please provide Value below ten: \c"
read -r value
if [ $value -le 10 ]
then
echo "You provided value is $value"
touch /tmp/test{1..100}.txt
echo "Script completed successfully"
fi
#Various options in if
foo=4
if [ $foo -ge 3 ]; then
echo "foo is greater than or equal to 3"
fi
if test $foo -ge 3; then
echo "foo is greater than or equal to 3"
fi
#Following code is only for demo.
#This file is not coded for the same.
#Please refer below url for an explanation on the below examples
# https://acloudguru.com/blog/engineering/conditions-in-bash-scripting-if-statements
regularfile="nestedif.sh"
readablefile="nestedif.sh"
if [ -f regularfile ]; then #-f
echo "Regular file"
fi
if [ -r readablefile]; then #-r
echo "Readablefile"
fi
if [ "$stringvar" == "tux" ]; then
echo "equal strings"
fi
if [ ! -f regularfile ]; then
echo "not regular file"
fi
if [ -L symboliclink ]; then
echo "Link"
fi
if [ -z "$emptystring" ]; then
echo "empty string"
fi
if [[ "$stringvar" == *string* ]]; then
echo "Double bracket - refer https://acloudguru.com/blog/engineering/conditions-in-bash-scripting-if-statements"
fi
if [[ "$stringvar" == *[sS]tring* ]]; then
echo "empty string"
fi
if [[ $stringvarwithspaces != foo ]]; then
echo "empty string"
fi
if [ -a *.sh ]; then #Single bracket
echo "empty string"
fi
if [[ -a *.sh ]]; then #Double bracket
echo "empty string"
fi
if [[ $num -eq 3 && "$stringvar" == foo ]]; then
echo "empty string"
fi
if (( $num <= 5 )); then
echo "empty string"
fi
# END #