| 1 | ---
|
| 2 | title: Mini Languages (Oils Reference)
|
| 3 | all_docs_url: ..
|
| 4 | body_css_class: width40
|
| 5 | default_highlighter: oils-sh
|
| 6 | preserve_anchor_case: yes
|
| 7 | ---
|
| 8 |
|
| 9 | <div class="doc-ref-header">
|
| 10 |
|
| 11 | [Oils Reference](index.html) —
|
| 12 | Chapter **Mini Languages**
|
| 13 |
|
| 14 | </div>
|
| 15 |
|
| 16 | This chapter describes "mini-languages" like glob patterns and brace expansion.
|
| 17 |
|
| 18 | In contrast, the main sub languages of YSH are [command](chap-cmd-lang.html),
|
| 19 | [word](chap-word-lang.html), and [expression](chap-expr-lang.html).
|
| 20 |
|
| 21 | <span class="in-progress">(in progress)</span>
|
| 22 |
|
| 23 | <div id="dense-toc">
|
| 24 | </div>
|
| 25 |
|
| 26 | <h2 id="sublang">Other Shell Sublanguages</h2>
|
| 27 |
|
| 28 | ## Arithmetic
|
| 29 |
|
| 30 | ### arith-context
|
| 31 |
|
| 32 | Arithmetic expressions are parsed and evaluated in many parts of POSIX shell
|
| 33 | and bash.
|
| 34 |
|
| 35 | Static:
|
| 36 |
|
| 37 | a=$(( x + 1 )) # POSIX shell
|
| 38 |
|
| 39 | # bash
|
| 40 | (( a = x + 1 ))
|
| 41 |
|
| 42 | for (( i = 0; i < n; ++i )); do
|
| 43 | echo $i
|
| 44 | done
|
| 45 |
|
| 46 | Dynamic:
|
| 47 |
|
| 48 | [[ 5 -eq 3+x ]] # but not test 5 -eq 3+x
|
| 49 |
|
| 50 | Array index contexts:
|
| 51 |
|
| 52 | echo ${a[i+1]} # get
|
| 53 | echo ${#a[i+1]} # calculate
|
| 54 |
|
| 55 | a[i+1]=foo # set
|
| 56 |
|
| 57 | printf -v 'a[i+1]' # assign to this location
|
| 58 | unset 'a[i+1]' # unset location
|
| 59 |
|
| 60 | echo ${a[@] : i+1 : i+2 } # bash slicing
|
| 61 |
|
| 62 | ### sh-numbers
|
| 63 |
|
| 64 | ### sh-arith
|
| 65 |
|
| 66 | ### sh-logical
|
| 67 |
|
| 68 | ### sh-bitwise
|
| 69 |
|
| 70 | ## Boolean
|
| 71 |
|
| 72 | ### bool-expr
|
| 73 |
|
| 74 | ### bool-infix
|
| 75 |
|
| 76 | ### bool-path
|
| 77 |
|
| 78 | ### bool-str
|
| 79 |
|
| 80 | ### bool-other
|
| 81 |
|
| 82 | ## Patterns
|
| 83 |
|
| 84 | ### glob-pat
|
| 85 |
|
| 86 | TODO: glob syntax
|
| 87 |
|
| 88 | ### extglob
|
| 89 |
|
| 90 | TODO: extended glob syntax
|
| 91 |
|
| 92 | ### regex
|
| 93 |
|
| 94 | Part of [dbracket](chap-cmd-lang.html#dbracket)
|
| 95 |
|
| 96 | ## Other Sublang
|
| 97 |
|
| 98 | ### braces
|
| 99 |
|
| 100 | ### histsub
|
| 101 |
|
| 102 | History substitution uses `!`.
|
| 103 |
|
| 104 | ### char-escapes
|
| 105 |
|
| 106 | These backslash escape sequences are used in [echo
|
| 107 | -e](chap-builtin-cmd.html#echo), [printf](chap-builtin-cmd.html#printf), and in
|
| 108 | C-style strings like `$'foo\n'`:
|
| 109 |
|
| 110 | \\ backslash
|
| 111 | \a alert (BEL)
|
| 112 | \b backspace
|
| 113 | \c stop processing remaining input
|
| 114 | \e the escape character \x1b
|
| 115 | \f form feed
|
| 116 | \n newline
|
| 117 | \r carriage return
|
| 118 | \t tab
|
| 119 | \v vertical tab
|
| 120 | \xHH the byte with value HH, in hexadecimal
|
| 121 | \uHHHH the unicode char with value HHHH, in hexadecimal
|
| 122 | \UHHHHHHHH the unicode char with value HHHHHHHH, in hexadecimal
|
| 123 |
|
| 124 | Also:
|
| 125 |
|
| 126 | \" Double quote.
|
| 127 |
|
| 128 | Inconsistent octal escapes:
|
| 129 |
|
| 130 | \0NNN echo -e '\0123'
|
| 131 | \NNN printf '\123'
|
| 132 | echo $'\123'
|
| 133 |
|
| 134 | TODO: Verify other differences between `echo -e`, `printf`, and `$''`. See
|
| 135 | `frontend/lexer_def.py`.
|
| 136 |
|