Please sign in to comment.
Set `pipefail' and `lastpipe' for better debugging
`true <<< $(false)` would always be true, we'd never catch the failure in the command substitution red handed. Instead, we use `foo | bar` with the `pipefail' shell option to catch the failure anywhere in the pipeline. Also, enable `lastpipe' so `bar` can run in the current shell instead of in a subshell, so variable assignments in `bar` don't get lost after the pipeline. Another subtle issue with `bar <<< "$(foo)"` is the output of `foo` will be altered, with trailing newlines stripped and one newline appended. This behavior may be fine in most cases, some may even find it desirable for the default `read` behavior which uses newline as line delimiter, but sometimes `foo | bar` is preferable since it does not modify the output of `foo` in any way. `foo | bar` is nicer for the `read -n 1` while loop which takes a string $region_select_action as input, since it does not append a newline so we don't read in a null at the end. But when piping to `read`, we must be careful not to trigger an error by reaching EOF. e.g., printf '%s' a | read # PIPESTATUS 0 1 printf '%s\n' a | read # PIPESTATUS 0 0 printf '%s\0' a | read -d '' # PIPESTATUS 0 0 For this reason, we add '\n' to the output of several functions.
- Loading branch information...