Why Sponsor Oils? | source | all docs for version 0.22.0 | all versions | oilshell.org
Warning: Work in progress! Leave feedback on Zulip or Github if you'd like this doc to be updated.
Strings are the most important data structure in shell. YSH makes them easier and safer!
This doc addresses these questions:
Shell Features:
YSH Features:
${x|html}
, etc.${.myproc arg1}
, etc.
"<h2>$x</h2>"html
$[x]
(square brackets)${.myproc arg1}
.\n
for newline.
You have to use the third form.Preferences:
$[]
interpolation${}
interpolationecho unquoted # bare words are allowed in command mode
echo 'with spaces' # single quoted string
var s = 'with spaces'
# Raw single quoted string, to emphasize literal backslashes
var s = r'C:\Program Files\'
# C-escaped single quoted string
var line = $'foo\n'
# double quoted with safe interpolation (TODO)
echo "<p>hello $[name]</p>" # default_escaper must be set
echo "<p>hello ${name|html}</p>" # explicit escaper
# double quoted with unsafe interpolation
echo "hello $name"
echo "hello ${name}_suffix" # braces delimit variable name
echo $(date +%x) # command sub
Still TODO:
echo ${.myproc arg1}
cat <<< '''
one
two
'''
cat <<< $'''
mu = \u{3bc}
nul = \x00
'''
var s = """
multiline with ${vars}
$(date +%x)
${.myproc arg1}
"""
Shell is unique! You don't have to quote strings.
and quoted strings in expression mode
r'C:\Program Files\'
parse_raw_strings
$'foo\n'
TODO: explain the difference.
This is different! It's data and not code. Analogy to JSON.
$[x]
(TODO)$[x]
for safe interpolation
shopt --set default_escaper
${x|html}
(TODO)${x|html}
for safe interpolationNote you can have bugs if you use the wrong escaper!
$x
(may be unsafe)$x
or ${x}
Note that you should not use "${var}"
in YSH code. Use $var
or
${var}
because of simple word evaluation.
$(echo hi)
${.myproc}
(stdout capture)Note that only words are allowed here; not full commands. Wrap other commands in a proc.
write_to_buffer
TODO:
echo ${.myproc foo|html} # I think this should be supported
For ${x|html}
and ${.myproc|html}
TODO
TODO
"$str1$str2"
Or "${str1}${str2}"
s ++ t
valid?. It isn't necessary for strings and lists
:| @a @b |
is the same for lists[*a, *b]
{d, **e}
might be bettersetvar s = "${s}${suffix}"
Since there is no ++
operator, there is no ++=
operator.
echo
, printf
, write
, and ${.myproc}
(write_to_buffer
)echo, printf, and write have their output captured.
proc p(arg) {
### A proc that has its output captured quickly.
echo $arg
write two
const x = 'three'
printf '%s\n' $x
# newline for interactive testing, but not when captured
if ! shopt -q write_to_buffer {
echo
}
}
echo ${.p one} # $'one\ntwo\nthree\n'
append
and join
var buf = :| |
append 'one ' (buf)
append $'two\n' (buf)
echo $[join(buf)]
$(echo hi)
$((1 + 2))
$[1 + 2]
${x%%prefix}
and so forth
$""
for localization?