1 ## oils_failures_allowed: 1
2 ## our_shell: ysh
3
4 #### shSplit() respects IFS
5
6 var s = ' aa a bb b '
7
8 argv.py @[shSplit(s)]
9
10 setvar IFS = 'a'
11
12 argv.py @[shSplit(s)]
13
14 setvar IFS = 'b'
15
16 argv.py @[shSplit(s)]
17
18 ## STDOUT:
19 ['aa', 'a', 'bb', 'b']
20 [' ', '', ' ', ' bb b ']
21 [' aa a ', '', ' ', ' ']
22 ## END
23
24
25 #### getVar() gets global or local vars
26
27 # compare with shvarGet(), which does dynamic scope
28
29 proc my-proc {
30 var mylocal = 43
31
32 echo g=$[getVar('g')]
33 echo mylocal=$[getVar('mylocal')]
34
35 # the whole purpose is dynamic variable names / dynamic binding
36 var prefix = 'my'
37 echo mylocal=$[getVar(prefix ++ 'local')]
38
39 echo not_global_or_local=$[getVar('not_global_or_local')]
40 }
41
42 proc main {
43 var not_global_or_local = 42
44 my-proc
45 }
46
47 var g = 'global'
48
49 main
50
51 ## STDOUT:
52 g=global
53 mylocal=43
54 mylocal=43
55 not_global_or_local=null
56 ## END
57
58 #### ASCII upper() lower()
59
60 var x = 'abc-'
61 var y = 'XYZ!'
62
63 echo $x
64 echo $y
65 echo
66
67 echo $[x => upper()]
68 echo $[x => lower()]
69 echo $[y => upper()]
70 echo $[y => lower()]
71
72 ## STDOUT:
73 abc-
74 XYZ!
75
76 ABC-
77 abc-
78 XYZ!
79 xyz!
80 ## END
81
82 #### Unicode upper() lower()
83
84 # Adapted from spec/var-op-bash
85
86 # https://www.utf8-chartable.de/unicode-utf8-table.pl
87
88 var x = u'\u{C0}\u{C8}' # upper grave
89 var y = u'\u{E1}\u{E9}' # lower acute
90
91 echo $x
92 echo $y
93 echo
94
95 echo $[x => upper()]
96 echo $[x => lower()]
97 echo $[y => upper()]
98 echo $[y => lower()]
99
100 ## STDOUT:
101 ÀÈ
102 áé
103 ## END