Skip to main content
Commonmark migration
Source Link

If a process substitution is expanded as an argument to a function, expanded to an environment variable during calling of a function, or expanded to any assignment within a function, the process substitution will be "held open" for use by any command within the function or its callees, until the function in which it was set returns. If the same variable is set again within a callee, unless the new variable is local, the previous process substitution is closed and will be unavailable to the caller when the callee returns.

 

In essence, process substitutions expanded to variables within functions remain open until the function in which the process substitution occured returns - even when assigned to locals that were set by a function's caller. Dynamic scope doesn't protect them from closing.

If a process substitution is expanded as an argument to a function, expanded to an environment variable during calling of a function, or expanded to any assignment within a function, the process substitution will be "held open" for use by any command within the function or its callees, until the function in which it was set returns. If the same variable is set again within a callee, unless the new variable is local, the previous process substitution is closed and will be unavailable to the caller when the callee returns.

 

In essence, process substitutions expanded to variables within functions remain open until the function in which the process substitution occured returns - even when assigned to locals that were set by a function's caller. Dynamic scope doesn't protect them from closing.

If a process substitution is expanded as an argument to a function, expanded to an environment variable during calling of a function, or expanded to any assignment within a function, the process substitution will be "held open" for use by any command within the function or its callees, until the function in which it was set returns. If the same variable is set again within a callee, unless the new variable is local, the previous process substitution is closed and will be unavailable to the caller when the callee returns.

In essence, process substitutions expanded to variables within functions remain open until the function in which the process substitution occured returns - even when assigned to locals that were set by a function's caller. Dynamic scope doesn't protect them from closing.

local -r
Source Link
ravron
  • 133
  • 4
doit() { readonlylocal -r FOO=<(echo hi) cat $FOO } doit # bash 3.2.57: $ ./test.sh hi # bash 4.4.19: $ ./test.sh cat: /dev/fd/63: Bad file descriptor 
doit() { readonly FOO=<(echo hi) cat $FOO } doit # bash 3.2.57: $ ./test.sh hi # bash 4.4.19: $ ./test.sh cat: /dev/fd/63: Bad file descriptor 
doit() { local -r FOO=<(echo hi) cat $FOO } doit # bash 3.2.57: $ ./test.sh hi # bash 4.4.19: $ ./test.sh cat: /dev/fd/63: Bad file descriptor 
edited body
Source Link
ravron
  • 133
  • 4
doit() { readonly FOO=<(echo hi) cat $FOO } doit # Bashbash 3.2.57: $ ./test.sh hi # bash 4.4.19: $ ./test.sh cat: /dev/fd/63: Bad file descriptor 
doit() { readonly FOO=<(echo hi) cat $FOO } doit # Bash 3.2.57: $ ./test.sh hi # bash 4.4.19: $ ./test.sh cat: /dev/fd/63: Bad file descriptor 
doit() { readonly FOO=<(echo hi) cat $FOO } doit # bash 3.2.57: $ ./test.sh hi # bash 4.4.19: $ ./test.sh cat: /dev/fd/63: Bad file descriptor 
Note bash versions
Source Link
ravron
  • 133
  • 4
Loading
added 19 characters in body
Source Link
ravron
  • 133
  • 4
Loading
Source Link
ravron
  • 133
  • 4
Loading