github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/parser/array.md (about) 1 # Array (`@`) Token 2 3 > Expand values as an array 4 5 ## Description 6 7 The array token is used to tell Murex to expand the string as multiple 8 parameters (an array) rather than as a single parameter string. 9 10 11 12 ## Examples 13 14 **ASCII variable names:** 15 16 ``` 17 » $example = "foobar" 18 » out $example 19 foobar 20 ``` 21 22 **Unicode variable names:** 23 24 Variable names can be non-ASCII however they have to be surrounded by 25 parenthesis. eg 26 27 ``` 28 » $(比如) = "举手之劳就可以使办公室更加环保,比如,使用再生纸。" 29 » out $(比如) 30 举手之劳就可以使办公室更加环保,比如,使用再生纸。 31 ``` 32 33 **Infixing inside text:** 34 35 Sometimes you need to denote the end of a variable and have text follow on. 36 37 ``` 38 » $partial_word = "orl" 39 » out "Hello w$(partial_word)d!" 40 Hello world! 41 ``` 42 43 **Variables are tokens:** 44 45 Please note the new line (`\n`) character. This is not split using `$`: 46 47 ``` 48 » $example = "foo\nbar" 49 ``` 50 51 Output as a string: 52 53 ``` 54 » out $example 55 foo 56 bar 57 ``` 58 59 Output as an array: 60 61 ``` 62 » out @example 63 foo bar 64 ``` 65 66 The string and array tokens also works for subshells: 67 68 ``` 69 » out ${ %[Mon..Fri] } 70 ["Mon","Tue","Wed","Thu","Fri"] 71 72 » out @{ %[Mon..Fri] } 73 Mon Tue Wed Thu Fri 74 ``` 75 76 > `out` will take an array and output each element, space delimited. Exactly 77 > the same how `echo` would in Bash. 78 79 **Variable as a command:** 80 81 If a variable is used as a commend then Murex will just print the content of 82 that variable. 83 84 ``` 85 » $example = "Hello World!" 86 87 » $example 88 Hello World! 89 ``` 90 91 ## Detail 92 93 Since arrays are expanded over multiple parameters, you cannot expand an array 94 inside quoted strings like you can with a string variable: 95 96 ``` 97 » out "foo ${ ja [1..5] } bar" 98 foo ["1","2","3","4","5"] bar 99 100 » out "foo @{ ja [1..5] } bar" 101 foo 1 2 3 4 5 bar 102 103 » %(${ ja [1..5] }) 104 ["1","2","3","4","5"] 105 106 » %(@{ ja: [1..5] }) 107 @{ ja [1..5] } 108 ``` 109 110 ## See Also 111 112 * [Reserved Variables](../user-guide/reserved-vars.md): 113 Special variables reserved by Murex 114 * [Tilde (`~`) Token](../parser/tilde.md): 115 Home directory path variable 116 * [`"Double Quote"`](../parser/double-quote.md): 117 Initiates or terminates a string (variables expanded) 118 * [`%(Brace Quote)`](../parser/brace-quote.md): 119 Initiates or terminates a string (variables expanded) 120 * [`'Single Quote'`](../parser/single-quote.md): 121 Initiates or terminates a string (variables not expanded) 122 * [`(brace quote)`](../parser/brace-quote-func.md): 123 Write a string to the STDOUT without new line (deprecated) 124 * [`ja` (mkarray)](../commands/ja.md): 125 A sophisticated yet simply way to build a JSON array 126 * [`out`](../commands/out.md): 127 Print a string to the STDOUT with a trailing new line character 128 * [`set`](../commands/set.md): 129 Define a local variable and set it's value 130 * [`string` (stringing)](../types/str.md): 131 string (primitive) 132 133 <hr/> 134 135 This document was generated from [gen/parser/variables_doc.yaml](https://github.com/lmorg/murex/blob/master/gen/parser/variables_doc.yaml).