| 1 | ---
|
| 2 | in_progress: yes
|
| 3 | body_css_class: width40 help-body
|
| 4 | default_highlighter: oils-sh
|
| 5 | preserve_anchor_case: yes
|
| 6 | ---
|
| 7 |
|
| 8 | Word Language
|
| 9 | ===
|
| 10 |
|
| 11 | This chapter in the [Oils Reference](index.html) describes the word language
|
| 12 | for OSH and YSH.
|
| 13 |
|
| 14 | <div id="toc">
|
| 15 | </div>
|
| 16 |
|
| 17 | <h2 id="expression">Expressions to Words</h2>
|
| 18 |
|
| 19 | ### expr-sub
|
| 20 |
|
| 21 | ### expr-splice
|
| 22 |
|
| 23 | ### var-splice
|
| 24 |
|
| 25 | <h2 id="formatting">Formatting Typed Data as Strings</h2>
|
| 26 |
|
| 27 | ### ysh-printf
|
| 28 |
|
| 29 | ### ysh-format
|
| 30 |
|
| 31 |
|
| 32 | ## Quotes
|
| 33 |
|
| 34 | ### osh-string
|
| 35 |
|
| 36 | - Single quotes
|
| 37 | - Double Quotes
|
| 38 | - C-style strings: `$'\n'`
|
| 39 |
|
| 40 | TODO: elaborate
|
| 41 |
|
| 42 | ### ysh-string
|
| 43 |
|
| 44 | YSH strings in the word language are the same as in the expression language.
|
| 45 |
|
| 46 | See [ysh-string in chap-expr-lang](chap-expr-lang.html#ysh-string).
|
| 47 |
|
| 48 | ### triple-quoted
|
| 49 |
|
| 50 | Triple-quoted in the word language are the same as in the expression language.
|
| 51 |
|
| 52 | See [triple-quoted in chap-expr-lang](chap-expr-lang.html#triple-quoted).
|
| 53 |
|
| 54 | ### tagged-str
|
| 55 |
|
| 56 | Not done.
|
| 57 |
|
| 58 | ## Substitutions
|
| 59 |
|
| 60 | ### command-sub
|
| 61 |
|
| 62 | Executes a command and captures its stdout.
|
| 63 |
|
| 64 | OSH has shell-compatible command sub like `$(echo hi)`. If a trailing newline
|
| 65 | is returned, it's removed:
|
| 66 |
|
| 67 | $ hostname
|
| 68 | example.com
|
| 69 |
|
| 70 | $ echo "/tmp/$(hostname)"
|
| 71 | /tmp/example.com
|
| 72 |
|
| 73 | YSH has spliced command subs, enabled by `shopt --set parse_at`. The reuslt is
|
| 74 | a **List** of strings, rather than a single string.
|
| 75 |
|
| 76 | $ write -- @(echo foo; echo 'with spaces')
|
| 77 | foo
|
| 78 | with-spaces
|
| 79 |
|
| 80 | The command's stdout parsed as the "J8 Lines" format, where each line is
|
| 81 | either:
|
| 82 |
|
| 83 | 1. An unquoted string, which must be valid UTF-8. Whitespace is allowed, but
|
| 84 | not other ASCII control chars.
|
| 85 | 2. A quoted J8 string (JSON style `""` or J8-style `b'' u'' ''`)
|
| 86 | 3. An **ignored** empty line
|
| 87 |
|
| 88 | See [J8 Notation](../j8-notation.html) for more details.
|
| 89 |
|
| 90 | ### var-sub
|
| 91 |
|
| 92 | Evaluates to the value of a variable:
|
| 93 |
|
| 94 | $ x=X
|
| 95 | $ echo $x ${x}
|
| 96 | X X
|
| 97 |
|
| 98 | ### arith-sub
|
| 99 |
|
| 100 | Shell has C-style arithmetic:
|
| 101 |
|
| 102 | $ echo $(( 1 + 2*3 ))
|
| 103 | 7
|
| 104 |
|
| 105 | ### tilde-sub
|
| 106 |
|
| 107 | Used as a shortcut for a user's home directory:
|
| 108 |
|
| 109 | ~/src # my home dir
|
| 110 | ~bob/src # user bob's home dir
|
| 111 |
|
| 112 | ## Var Ops
|
| 113 |
|
| 114 | ### op-test
|
| 115 |
|
| 116 | ### op-strip
|
| 117 |
|
| 118 | ### op-replace
|
| 119 |
|
| 120 | ### op-index
|
| 121 |
|
| 122 | ${a[i+1]}
|
| 123 |
|
| 124 | ### op-slice
|
| 125 |
|
| 126 | ### op-format
|
| 127 |
|
| 128 | ${x@P} evaluates x as a prompt string, e.g. the string that would be printed if
|
| 129 | PS1=$x.
|
| 130 |
|