Skip to content

Latest commit

 

History

History
130 lines (77 loc) · 2.18 KB

chap-word-lang.md

File metadata and controls

130 lines (77 loc) · 2.18 KB
in_progress body_css_class default_highlighter preserve_anchor_case
true
width40 help-body
oils-sh
true

Word Language

This chapter in the Oils Reference describes the word language for OSH and YSH.

Expressions to Words

expr-sub

expr-splice

var-splice

Formatting Typed Data as Strings

ysh-printf

ysh-format

Quotes

osh-string

  • Single quotes
  • Double Quotes
  • C-style strings: $'\n'

TODO: elaborate

ysh-string

YSH strings in the word language are the same as in the expression language.

See ysh-string in chap-expr-lang.

triple-quoted

Triple-quoted in the word language are the same as in the expression language.

See triple-quoted in chap-expr-lang.

tagged-str

Not done.

Substitutions

command-sub

Executes a command and captures its stdout.

OSH has shell-compatible command sub like $(echo hi). If a trailing newline is returned, it's removed:

$ hostname
example.com

$ echo "/tmp/$(hostname)"
/tmp/example.com

YSH has spliced command subs, enabled by shopt --set parse_at. The reuslt is a List of strings, rather than a single string.

$ write -- @(echo foo; echo 'with spaces')
foo
with-spaces

The command's stdout parsed as the "J8 Lines" format, where each line is either:

  1. An unquoted string, which must be valid UTF-8. Whitespace is allowed, but not other ASCII control chars.
  2. A quoted J8 string (JSON style "" or J8-style b'' u'' '')
  3. An ignored empty line

See J8 Notation for more details.

var-sub

Evaluates to the value of a variable:

$ x=X
$ echo $x ${x}
X X

arith-sub

Shell has C-style arithmetic:

$ echo $(( 1 + 2*3 ))
7

tilde-sub

Used as a shortcut for a user's home directory:

~/src     # my home dir
~bob/src  # user bob's home dir

Var Ops

op-test

op-strip

op-replace

op-index

${a[i+1]}

op-slice

op-format

${x@P} evaluates x as a prompt string, e.g. the string that would be printed if PS1=$x.