[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: why did coprocs fd not exist, in this sample submissed on an issue a
From: |
Chet Ramey |
Subject: |
Re: why did coprocs fd not exist, in this sample submissed on an issue as answer |
Date: |
Thu, 30 Sep 2021 15:31:11 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 |
On 9/30/21 12:55 PM, Alex fxmbsw7 Ratchev wrote:
> s=ab34 ; awksplit() { gawk -v FS= -v RS=\\0 -v ORS=\\0 -e '{ gsub( /./,
> "\\\\& " ) ; print }' "$@" ; } ; declare -a "one=( $( awksplit <<<"$s" -v
> ORS= ) )" ; declare -p one ; [[ ! -v ser ]] && coproc ser { awksplit ; } ;
> ser() { printf %s\\0 "${@:2}" >&${ser[1]} ; declare -ga "$1=( $( <
> /proc/fd/$ser ) )" ; declare -p $1 ; } ; ser serial "$s"
>
> declare -a one=([0]="a" [1]="b" [2]="3" [3]="4")
> [1] 17511
> bash: /proc/fd/57: No such file or directory
> declare -a serial=()
>
> besides the [[ -v ser doesnt work, i suspect ser[0] may
coproc file descriptors are close-on-exec, plus the shell takes care to
close them when creating subshells. Stray file descriptors open to pipes
can cause deadlocks or prevent EOF delivery.
"The file descriptors
can be utilized as arguments to shell commands and redirections using
standard word expansions. Other than those created to execute command
and process substitutions, the file descriptors are not available in
subshells."
If you want a file descriptor that's not close-on-exec, use redirection
to copy it. But then you have to manage closing them yourself when it's
necessary.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/