source | all docs for version 0.10.1 | all versions | oilshell.org
When you turn on Oil, there are some shell constructs you can no longer use. We try to minimize the length of this list.
You don't need to read this doc if you're using bin/osh
, which is Oil in
its default POSIX- and bash-compatible mode. OSH is compatible by default.
shopt -s oil:basic
)Here are two things that Oil users should know about, one major and one minor:
The meaning of the POSIX construct ()
has changed, and the meaning of the
bash construct @()
has changed.
forkwait
for subshells rather than ()
(shopt -s parse_paren
)Subshells are uncommon in idiomatic Oil code, so they have the awkward name
forkwait
. Think of it as a sequence of the fork
builtin (for &
) and the
wait
builtin.
No:
( not_mutated=foo )
echo $not_mutated
Yes:
forkwait {
setvar not_mutated = 'foo'
}
echo $not_mutated
You don't need a subshell for some idioms:
No:
( cd /tmp; echo $PWD )
echo $PWD # not mutated
Yes:
cd /tmp {
echo $PWD
}
echo $PWD # restored
Justification: We're using parentheses for Oil expressions like
if (x > 0) { echo 'positive' }
and subshells are uncommon. Oil has blocks to save and restore state.
shopt -s parse_at
)No:
echo @(*.py|*.sh)
Use this Oil alias instead:
echo ,(*.py|*.sh)
Justification: Most people don't know about extended globs, and we want
explicitly split command subs like @(seq 3)
to work.
That is, Oil doesn't have implicit word splitting. Instead, it uses simple word evaluation.
@foo
must be quoted '@foo'
to preserve meaning (shopt -s parse_at
)=x
is disallowed as the first word in a command to avoid confusion with
Oil's =
operator.
'=x'
, but there's almost no reason to do that.This is the list of major features that's broken when you upgrade from OSH to Oil. Again, we try to minimize this list, and there are two tiers.
There are other features that are discouraged, like $(( x + 1 ))
, (( i++ ))
, [[ $s =~ $pat ]]
, and ${s%%prefix}
. These have better alternatives
in the Oil expression language, but they can still be used. See Oil vs. Shell
Idioms.