OSH Quirks

This document describes corner cases in OSH.

Related: Known Differences.

Table of Contents
For Bash Compatibility
The meaning of () on the RHS
Interactive Shell
With job control, the DEBUG trap is disabled for the last part of a pipeline
Related

For Bash Compatibility

The meaning of () on the RHS

In Oils, values are tagged with types like Str and AssocArray, as opposed to the locations of values (cells).

This statement binds an empty indexed array to the name x:

x=()  # indexed by integers

Quirk: When it's clear from the context, () means an empty associative array:

declare -A x=()  # indexed by strings, because of -A

This only applies when the array is empty. Otherwise the type is determined by the literal:

declare x=(one two)  # indexed array
declare x=(['k']=v)  # associative array

Redundant but OK:

declare -a x=(one two)  # indexed array
declare -A x=(['k']=v)  # associative array

Errors:

declare -A x=(one two)  # inconsistent
declare -a x=(['k']=v)  # inconsistent

Interactive Shell

With job control, the DEBUG trap is disabled for the last part of a pipeline

First, some background. These two shell features are fundamentally incompatible:

As evidence of this incompatibility, note that:


Now that we have that background, note that there's is a third feature that interacts: the DEBUG trap.

OSH emulates the bash DEBUG trap, which runs before "leaf" commands like echo hi, a=b, etc.

If we run this trap before the last part of a pipeline, and that part is run in the current shell (lastpipe), then the DEBUG trap makes an existing race condition worse.

For example, in

echo hi | cat

there's nothing stopping echo hi from finishing before cat is even started, which means that cat can't join the process group of the leader.

So we simply disable the DEBUG trap for the last part of the pipeline, but only when job control is enabled. This won't affect debugging batch programs.

Related issues in other shells:

Related

Generated on Tue, 30 Jul 2024 20:25:06 +0000