Debian Codegraph @

ex10.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 # Tip:
4 # If you're unsure how a certain condition might evaluate,
5 #+ test it in an if-test.
6
7 echoscip-shell system . . echo.
8
9 echoscip-shell system . . echo. "Testing \"0\""
10 if [scip-shell system . . `[`. 0 ] # zero
11 then
12 echoscip-shell system . . echo. "0 is true."
13 else # Or else ...
14 echoscip-shell system . . echo. "0 is false."
15 fi # 0 is true.
16
17 echoscip-shell system . . echo.
18
19 echoscip-shell system . . echo. "Testing \"1\""
20 if [scip-shell system . . `[`. 1 ] # one
21 then
22 echoscip-shell system . . echo. "1 is true."
23 else
24 echoscip-shell system . . echo. "1 is false."
25 fi # 1 is true.
26
27 echoscip-shell system . . echo.
28
29 echoscip-shell system . . echo. "Testing \"-1\""
30 if [scip-shell system . . `[`. -1 ] # minus one
31 then
32 echoscip-shell system . . echo. "-1 is true."
33 else
34 echoscip-shell system . . echo. "-1 is false."
35 fi # -1 is true.
36
37 echoscip-shell system . . echo.
38
39 echoscip-shell system . . echo. "Testing \"NULL\""
40 if [scip-shell system . . `[`. ] # NULL (empty condition)
41 then
42 echoscip-shell system . . echo. "NULL is true."
43 else
44 echoscip-shell system . . echo. "NULL is false."
45 fi # NULL is false.
46
47 echoscip-shell system . . echo.
48
49 echoscip-shell system . . echo. "Testing \"xyz\""
50 if [scip-shell system . . `[`. xyz ] # string
51 then
52 echoscip-shell system . . echo. "Random string is true."
53 else
54 echoscip-shell system . . echo. "Random string is false."
55 fi # Random string is true.
56
57 echoscip-shell system . . echo.
58
59 echoscip-shell system . . echo. "Testing \"\$xyz\""
60 if [scip-shell system . . `[`. $xyz ] # Tests if $xyz is null, but...
61 # it's only an uninitialized variable.
62 then
63 echoscip-shell system . . echo. "Uninitialized variable is true."
64 else
65 echoscip-shell system . . echo. "Uninitialized variable is false."
66 fi # Uninitialized variable is false.
67
68 echoscip-shell system . . echo.
69
70 echoscip-shell system . . echo. "Testing \"-n \$xyz\""
71 if [scip-shell system . . `[`. -n "$xyz" ] # More pedantically correct.
72 then
73 echoscip-shell system . . echo. "Uninitialized variable is true."
74 else
75 echoscip-shell system . . echo. "Uninitialized variable is false."
76 fi # Uninitialized variable is false.
77
78 echoscip-shell system . . echo.
79
80
81 xyz= # Initialized, but set to null value.
82
83 echoscip-shell system . . echo. "Testing \"-n \$xyz\""
84 if [scip-shell system . . `[`. -n "$xyz" ]
85 then
86 echoscip-shell system . . echo. "Null variable is true."
87 else
88 echoscip-shell system . . echo. "Null variable is false."
89 fi # Null variable is false.
90
91
92 echoscip-shell system . . echo.
93
94
95 # When is "false" true?
96
97 echoscip-shell system . . echo. "Testing \"false\""
98 if [scip-shell system . . `[`. "false" ] # It seems that "false" is just a string ...
99 then
100 echoscip-shell system . . echo. "\"false\" is true." #+ and it tests true.
101 else
102 echoscip-shell system . . echo. "\"false\" is false."
103 fi # "false" is true.
104
105 echoscip-shell system . . echo.
106
107 echoscip-shell system . . echo. "Testing \"\$false\"" # Again, uninitialized variable.
108 if [scip-shell system . . `[`. "$false" ]
109 then
110 echoscip-shell system . . echo. "\"\$false\" is true."
111 else
112 echoscip-shell system . . echo. "\"\$false\" is false."
113 fi # "$false" is false.
114 # Now, we get the expected result.
115
116 # What would happen if we tested the uninitialized variable "$true"?
117
118 echoscip-shell system . . echo.
119
120 exit 0