1 #!/usr/bin/env bash
2
3 #### Eval
4 eval "a=3"
5 echo $a
6 ## stdout: 3
7
8 #### Source
9 lib=$TMP/spec-test-lib.sh
10 echo 'LIBVAR=libvar' > $lib
11 . $lib # dash doesn't have source
12 echo $LIBVAR
13 ## stdout: libvar
14
15 #### Source nonexistent
16 source /nonexistent/path
17 echo status=$?
18 ## stdout: status=1
19 ## OK dash/zsh stdout: status=127
20
21 #### Source with no arguments
22 source
23 echo status=$?
24 ## stdout: status=1
25 ## OK bash stdout: status=2
26 ## OK dash stdout: status=127
27
28 #### Source with arguments
29 . spec/testdata/show-argv.sh foo bar # dash doesn't have source
30 ## STDOUT:
31 show-argv: foo bar
32 ## END
33 ## N-I dash STDOUT:
34 show-argv:
35 ## END
36
37 #### Source from a function, mutating argv and defining a local var
38 f() {
39 . spec/testdata/source-argv.sh # no argv
40 . spec/testdata/source-argv.sh args to src # new argv
41 echo $@
42 echo foo=$foo # defined in source-argv.sh
43 }
44 f args to func
45 echo foo=$foo # not defined
46 ## STDOUT:
47 source-argv: args to func
48 source-argv: args to src
49 to func
50 foo=foo_val
51 foo=
52 ## END
53 ## N-I dash STDOUT:
54 source-argv: args to func
55 source-argv: to func
56 func
57 foo=foo_val
58 foo=
59 ## END