]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/new-exp8.sub
Bash-4.4 patch 19
[thirdparty/bash.git] / tests / new-exp8.sub
1 pat1='str'
2 pat2='[^;]'
3 pat3='[[:alnum:]_]'
4 pat4='[[:alnum:]][[fu]b'
5 pat5='?tr'
6 pat6='?tr\'
7 pat7='[[:alnum:]]_'
8 pat8='*tr'
9
10 declare z="start"
11 declare NUM=1000
12
13 #----------------------------------
14 # create a long string with ';'
15 #----------------------------------
16 for ((i=0; i<$NUM; i++)); do
17 z="$z;string$i"
18 done
19
20 #z="$z;string;foo"
21
22 #------------------------------
23 # delete everything except ';'
24 #------------------------------
25
26 # try different patterns here
27 x="${z//$pat1}"
28 echo $x
29 x="${z//$pat2}"
30 echo $x
31 x="${z//$pat3}"
32 echo $x
33 x="${z//$pat4}"
34 echo $x
35 x="${z//$pat5}"
36 echo $x
37 x="${z//$pat6}"
38 echo $x
39 x="${z//$pat7}"
40 echo $x
41 x="${z//$pat8}"
42 echo $x
43
44
45 declare z="start"
46 declare NUM=1000
47
48 #----------------------------------
49 # create a long string with ';'
50 #----------------------------------
51 for ((i=0; i<$NUM; i++)); do
52 z="$z;string$i"
53 done
54
55 #z="$z;string;foo"
56
57 #------------------------------
58 # delete everything except ';'
59 #------------------------------
60
61 # try different patterns here
62 x="${z//[^;]}"
63 echo $x
64 x="${z/#[^;][^;]}"
65 echo $x
66 x="${z/%[^;][^;]}"
67 echo $x
68
69 export LANG=C LC_ALL=C LC_CTYPE=C
70
71 # try different patterns here
72 x="${z//$pat1}"
73 echo $x
74 x="${z//$pat2}"
75 echo $x
76 x="${z//$pat3}"
77 echo $x
78 x="${z//$pat4}"
79 echo $x
80 x="${z//$pat5}"
81 echo $x
82 x="${z//$pat6}"
83 echo $x
84 x="${z//$pat7}"
85 echo $x
86 x="${z//$pat8}"
87 echo $x
88
89 # try different patterns here
90 x="${z//[^;]}"
91 echo $x
92 x="${z/#[^;][^;]}"
93 echo $x
94 x="${z/%[^;][^;]}"
95 echo $x
96
97 # post-bash-4.3 changes to make pattern replacement honor nocasematch variable
98 unset string
99 string=abcd
100
101 shopt -s nocasematch
102
103 echo ${string//A/z}
104 echo ${string//BC/x}
105 echo ${string//[BC]/x}
106 echo ${string//[bC]/x}
107 echo ${string//?/z}
108
109 LC_ALL=C
110 echo ${string//A/z}
111 echo ${string//BC/x}
112 echo ${string//[BC]/x}
113 echo ${string//[bC]/x}
114 echo ${string//?/z}
115
116