OILS / demo / osh-crash.sh View on Github | oilshell.org

63 lines, 35 significant
1#!/usr/bin/env bash
2#
3# Usage:
4# ./osh-crash.sh <function name>
5
6set -o nounset
7set -o pipefail
8set -o errexit
9
10g() {
11 readonly g=1
12 readonly -a bash_array=(a b)
13 bash_array[5]=z
14
15 echo foo > $bar
16}
17
18f() {
19 shift
20 local flocal=flocal
21 FOO=bar g A B
22}
23
24main() {
25 f a b c
26}
27
28run-with-osh() {
29 OILS_CRASH_DUMP_DIR=_tmp bin/osh $0 main "$@"
30}
31
32_do-subshell() {
33 echo PID=$$
34 ( f a b c )
35}
36
37# Note: we get two difference crash dumps, with two different stacks.
38#
39# That's because we call through $0.
40
41do-subshell() {
42 # clear environment so it's smaller
43 env -i OILS_CRASH_DUMP_DIR=_tmp \
44 bin/osh $0 _do-subshell "$@"
45}
46
47_pipeline() {
48 # All of these show multiple errors
49
50 false | wc -l
51
52 #{ echo 1; false; echo 2; } | wc -l
53
54 #f() { echo 1; false; echo 2; }
55 #f | tac
56}
57
58do-pipeline() {
59 env -i PATH=$PATH OILS_CRASH_DUMP_DIR=_tmp \
60 bin/osh $0 _pipeline
61}
62
63"$@"