Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created November 2, 2012 16:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/4002611 to your computer and use it in GitHub Desktop.
Save ormaaj/4002611 to your computer and use it in GitHub Desktop.
trap scope
#!/usr/bin/env bash
# bash: line 3: declare: v: readonly variable
for fd in {a..d}; do
echo "$fd"
bash -x /dev/fd/"${!fd}"
done {ofd}<&0 <<\EOFA {a}<&0 <<\EOFB {b}<&0 <<\EOFC {c}<&0 <<\EOFD {d}<&0 <&${ofd}
tt() { typeset -r v=; }
t() { tt; }
ff() {
typeset -r v=
exit
}
f() { ff; }
trap t EXIT
f
EOFA
tt() { typeset -r v=; }
t() { tt; }
ff() {
typeset -r v=
exit
}
f() { ff; }
trap t EXIT;
f
EOFB
tt() { typeset -r v=; }
t() { tt; }
ff() {
typeset -r v=
exit
}
trap t EXIT;
ff
EOFC
tt() { typeset -r v=; }
ff() {
typeset -r v=
exit
}
f() { ff; }
trap tt EXIT;
f
EOFD
# vim: set fenc=utf-8 ff=unix ts=4 sts=4 sw=4 ft=sh nowrap et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment