Configuration Information [Automatically generated, do not change]: Machine: x86_64
OS: linux-gnu Compiler: gcc Compilation CFLAGS: -g -O2 uname output: Linux fs 6.5.11-7-pve #1 SMP PREEMPT_DYNAMIC PMX 6.5.11-7 (2023-12-05T09:44Z) x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu Bash Version: 5.2 Patch Level: 21 Release Status: release Description: `declare -f` wrongly displays the `coproc my_command` statement. It adds the word COPROC after the `coproc` word. I use some kind of RPC in my scripts, so after several passes of the function, the line becomes: `coproc COPROC COPROC ... COPROC my_command` Repeat-By: # define a function: process() { coproc inotifywait -qm /home read -u ${COPROC[0]} event } # display it declare -f process process () { coproc COPROC inotifywait -qm /home; read -u ${COPROC[0]} event } # iterate 2 times (just to test): source <(declare -f process) source <(declare -f process) declare -f process process () { coproc COPROC COPROC COPROC inotifywait -qm /home; read -u ${COPROC[0]} event } Fix: # use curly braces: process() { coproc { inotifywait -qm /home; } read -u ${COPROC[0]} event } # in this case the word COPROC is added only once and further # calls does not change it, so the function works as expected. # But the drawback in this approach is that more processes are created. # It can be seen in pstree: test───test───inotifywait # In comparison with plain `coproc`: test───inotifywait