-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8_AutomatingDecisionMaking.sh
73 lines (64 loc) · 1.38 KB
/
8_AutomatingDecisionMaking.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
# Checking the exit status of commands
echo $?
# Using the test command
test $name=seb
[[ $name = Ganesh ]]
[[ $name = [Gg]???? ]]
[[ $var == var_val && $varB == "John" ]]
[ $var == Ganesh ] && [ $varB == "John" ]
# test strings
test -n $string # [ -n $string ], non-null string
test -z $string # [ -z $string ], null string
test $string1 != $string2
test $string1 == $string2
test $string1 > $string2
# test integers
test $int1 -eq $int2 # (( $int1 == $int2 )), [[ $int1 == $int2 ]], [ $int1 == $int2 ]]
test $int1 -ne $int2
test $int -lt $int2
# File test options
test -c $filename # Special character file test
test -d $dir # Is a directory
test -f $filename # Is a file
test -e $filename # file or directory exists
test -G $filename # file exists and owned by my group id
test -t $fd # true if FD is open on terminal
test -r $filename # has read permissions, -w, -x
test $file1 -nt $file2 # newer than
# See help test
# Conditional constructs
if command
then
echo "blala"
else
echo "blabla2"
fi
# if command; then echo "blabla"; fi
#if [ numeric/string exp ]
#if [[ string exp ]]
#if (( numerical exp ))
# null command
:
# Switch case
case $var in
value1)
echo "value1 !"
;;
*@*.com) # email pattern
echo "email !"
;;
*)
echo "other"
;;
esac
# Select
select var in apple pear banana
do
echo "blabla"
done
# Use break to exit the loop
select var in {0..1}
do
echo $var
break
done