1 |
#!/bin/bash |
2 |
# |
3 |
# NOTE: Could move tests/03-glob.sh here. |
4 |
|
5 |
### glob double quote escape |
6 |
echo "*.sh" |
7 |
# stdout: *.sh |
8 |
|
9 |
### glob single quote escape |
10 |
echo "*.sh" |
11 |
# stdout: *.sh |
12 |
|
13 |
### glob backslash escape |
14 |
echo \*.sh |
15 |
# stdout: *.sh |
16 |
|
17 |
### 1 char glob |
18 |
echo [t]ests |
19 |
# stdout: tests |
20 |
|
21 |
### 0 char glob -- does NOT work |
22 |
echo []tests |
23 |
# stdout: []tests |
24 |
|
25 |
### looks like glob at the start, but isn't |
26 |
echo [tests |
27 |
# stdout: [tests |
28 |
|
29 |
### looks like glob plus negation at the start, but isn't |
30 |
echo [!tests |
31 |
# stdout: [!tests |
32 |
|
33 |
### glob can expand to command and arg |
34 |
tests/echo.s[hz] |
35 |
# stdout: tests/echo.sz |
36 |
|
37 |
### glob after var expansion |
38 |
touch _tmp/a.A _tmp/aa.A _tmp/b.B |
39 |
f="_tmp/*.A" |
40 |
g="$f _tmp/*.B" |
41 |
echo $g |
42 |
# stdout: _tmp/a.A _tmp/aa.A _tmp/b.B |
43 |
|
44 |
### quoted var expansion with glob meta characters |
45 |
touch _tmp/a.A _tmp/aa.A _tmp/b.B |
46 |
f="_tmp/*.A" |
47 |
echo "[ $f ]" |
48 |
# stdout: [ _tmp/*.A ] |
49 |
|
50 |
### glob after "$@" expansion |
51 |
func() { |
52 |
echo "$@" |
53 |
} |
54 |
func '_tmp/*.B' |
55 |
# stdout: _tmp/*.B |
56 |
|
57 |
### glob after $@ expansion |
58 |
func() { |
59 |
echo $@ |
60 |
} |
61 |
func '_tmp/*.B' |
62 |
# stdout: _tmp/b.B |
63 |
|
64 |
### no glob after ~ expansion |
65 |
HOME=* |
66 |
echo ~/*.py |
67 |
# stdout: */*.py |
68 |
|
69 |
### store literal globs in array then expand |
70 |
touch _tmp/a.A _tmp/aa.A _tmp/b.B |
71 |
g=("_tmp/*.A" "_tmp/*.B") |
72 |
echo ${g[@]} |
73 |
# stdout: _tmp/a.A _tmp/aa.A _tmp/b.B |
74 |
# N-I dash/ash stdout-json: "" |
75 |
# N-I dash/ash status: 2 |
76 |
|
77 |
### glob inside array |
78 |
touch _tmp/a.A _tmp/aa.A _tmp/b.B |
79 |
g=(_tmp/*.A _tmp/*.B) |
80 |
echo "${g[@]}" |
81 |
# stdout: _tmp/a.A _tmp/aa.A _tmp/b.B |
82 |
# N-I dash/ash stdout-json: "" |
83 |
# N-I dash/ash status: 2 |
84 |
|
85 |
### glob with escaped - in char class |
86 |
touch _tmp/foo.- |
87 |
touch _tmp/c.C |
88 |
echo _tmp/*.[C-D] _tmp/*.[C\-D] |
89 |
# stdout: _tmp/c.C _tmp/c.C _tmp/foo.- |
90 |
|
91 |
### glob with char class expression |
92 |
# note: mksh doesn't support [[:punct:]] ? |
93 |
touch _tmp/e.E _tmp/foo.- |
94 |
echo _tmp/*.[[:punct:]E] |
95 |
# stdout: _tmp/e.E _tmp/foo.- |
96 |
# BUG mksh stdout: _tmp/*.[[:punct:]E] |
97 |
|
98 |
### glob double quotes |
99 |
# note: mksh doesn't support [[:punct:]] ? |
100 |
touch _tmp/\"quoted.py\" |
101 |
echo _tmp/\"*.py\" |
102 |
# stdout: _tmp/"quoted.py" |
103 |
|
104 |
### glob escaped |
105 |
# - mksh doesn't support [[:punct:]] ? |
106 |
# - python shell fails because \[ not supported! |
107 |
touch _tmp/\[abc\] _tmp/\? |
108 |
echo _tmp/\[???\] _tmp/\? |
109 |
# stdout: _tmp/[abc] _tmp/? |
110 |
|
111 |
### : escaped |
112 |
touch _tmp/foo.- |
113 |
echo _tmp/*.[[:punct:]] _tmp/*.[[:punct\:]] |
114 |
# stdout: _tmp/foo.- _tmp/*.[[:punct:]] |
115 |
# BUG mksh stdout: _tmp/*.[[:punct:]] _tmp/*.[[:punct:]] |
116 |
|
117 |
### Redirect to glob, not evaluated |
118 |
# This writes to *.F, not foo.F |
119 |
touch _tmp/f.F |
120 |
echo foo > _tmp/*.F |
121 |
cat '_tmp/*.F' |
122 |
# stdout: foo |
123 |
|