]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/varenv.sh
Imported from ../bash-2.0.tar.gz.
[thirdparty/bash.git] / tests / varenv.sh
1 #
2 # varenv.sh
3 #
4 # Test the behavior of the shell with respect to variable and environment
5 # assignments
6 #
7 expect()
8 {
9 echo expect "$@"
10 }
11
12 a=1
13 b=2
14 c=3
15 d=4
16 e=5
17 f=6 g=7 h=8
18
19 a=3 b=4 $CHMOD $MODE $FN
20
21 # This should echo "3 4" according to Posix.2
22 expect "3 4"
23 echo $a $b
24
25 set -k
26
27 # Assignment statements made when no words are left affect the shell's
28 # environment
29 a=5 b=6 $CHMOD c=7 $MODE d=8 $FN e=9
30
31 expect "5 6 7 8 9"
32 echo $a $b $c $d $e
33
34 $CHMOD f=7 $MODE g=8 $FN h=9
35 expect "7 8 9"
36 echo $f $g $h
37
38 set +k
39
40 # The temporary environment does not affect variable expansion, only the
41 # environment given to the command
42
43 export HOME=/usr/chet
44 expect $HOME
45 echo $HOME
46
47 expect $HOME
48 HOME=/a/b/c /bin/echo $HOME
49
50 expect $HOME
51 echo $HOME
52
53 # This should echo /a/b/c
54 expect /a/b/c
55 HOME=/a/b/c printenv HOME
56
57 set -k
58
59 # This should echo $HOME 9, NOT /a/b/c 9
60
61 expect "$HOME"
62 HOME=/a/b/c /bin/echo $HOME c=9
63 expect "$HOME 7"
64 echo $HOME $c
65
66 # I claim the next two echo calls should give identical output.
67 # ksh agrees, the System V.3 sh does not
68
69 expect "/a/b/c 9 /a/b/c"
70 HOME=/a/b/c $ECHO a=$HOME c=9
71 echo $HOME $c $a
72
73 expect "/a/b/c 9 /a/b/c"
74 HOME=/a/b/c a=$HOME c=9
75 echo $HOME $c $a
76 set +k
77
78 # How do assignment statements affect subsequent assignments on the same
79 # line?
80 expect "/a/b/c /a/b/c"
81 HOME=/a/b/c a=$HOME
82 echo $HOME $a
83
84 # The system V.3 sh does this wrong; the last echo should output "1 1",
85 # but the system V.3 sh has it output "2 2". Posix.2 says the assignment
86 # statements are processed left-to-right. bash and ksh output the right
87 # thing
88 c=1
89 d=2
90 expect "1 2"
91 echo $c $d
92 d=$c c=$d
93 expect "1 1"
94 echo $c $d
95
96 # just for completeness
97 unset d c
98 expect unset
99 echo ${d-unset}
100
101 # no output
102 export a
103 a=bcde
104 export a
105 /bin/true 2>/dev/null