Shell Language Deprecations

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.

Table of Contents
Right Now (shopt -s oil:basic)
Use forkwait for subshells rather than () (shopt -s parse_paren)
Some Extended Globs Can't Be Used (shopt -s parse_at)
Minor Breakages
That's It
Related

Right Now (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.

Use 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.

Some Extended Globs Can't Be Used (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.

Minor Breakages

That's It

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.

Related


Generated on Thu May 19 20:44:26 EDT 2022