~ubuntu-branches/ubuntu/trusty/abs-guide/trusty-proposed

« back to all changes in this revision

Viewing changes to ex9.sh

  • Committer: Package Import Robot
  • Author(s): Sandro Tosi
  • Date: 2014-01-01 12:26:22 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20140101122622-n04ky7hk3mt1x13l
Tags: 6.6-1
* New upstream release; thanks to Sébastien Villemot for the report;
  Closes: #733155
* debian/control
  - bump Standards-Version to 3.9.5 (no changes needed)
  - use packaging repository canonical URLs

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
a=375
7
7
hello=$a
 
8
#   ^ ^
8
9
 
9
10
#-------------------------------------------------------------------------
10
11
# No space permitted on either side of = sign when initializing variables.
22
23
 
23
24
 
24
25
echo hello    # hello
25
 
# Not a variable reference, just the string "hello" . . .
 
26
# Not a variable reference, just the string "hello" ...
26
27
 
27
28
echo $hello   # 375
28
29
#    ^          This *is* a variable reference.
29
30
echo ${hello} # 375
30
 
# Also a variable reference, as above.
 
31
#               Likewise a variable reference, as above.
31
32
 
32
33
# Quoting . . .
33
34
echo "$hello"    # 375
38
39
hello="A B  C   D"
39
40
echo $hello   # A B C D
40
41
echo "$hello" # A B  C   D
41
 
# As you see, echo $hello   and   echo "$hello"   give different results.
42
 
# Why?
 
42
# As we see, echo $hello   and   echo "$hello"   give different results.
43
43
# =======================================
44
44
# Quoting a variable preserves whitespace.
45
45
# =======================================
55
55
 
56
56
 
57
57
hello=    # Setting it to a null value.
58
 
echo "\$hello (null value) = $hello"
 
58
echo "\$hello (null value) = $hello"      # $hello (null value) =
59
59
#  Note that setting a variable to a null value is not the same as
60
60
#+ unsetting it, although the end result is the same (see below).
61
61
 
69
69
echo
70
70
echo "var1=$var1   var2=$var2   var3=$var3"
71
71
 
72
 
# May cause problems with older versions of "sh" . . .
 
72
# May cause problems with legacy versions of "sh" . . .
73
73
 
74
74
# --------------------------------------------------------------
75
75
 
102
102
uninitialized_variable=23       # Set it.
103
103
unset uninitialized_variable    # Unset it.
104
104
echo "uninitialized_variable = $uninitialized_variable"
 
105
                                # uninitialized_variable =
105
106
                                # It still has a null value.
106
107
echo
107
108