help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Why `if` and source can affect process substitution fd?


From: Peng Yu
Subject: [Help-bash] Why `if` and source can affect process substitution fd?
Date: Fri, 20 Sep 2019 19:32:05 -0500

Hi,

When `if` and `source` used together, the fd will be affected. Why is
it so? Is there way to not to affect the fd when `if` and `source` are
used together.

$ ./main.sh
/dev/fd/61 /dev/fd/60
/dev/fd/62 /dev/fd/61
$ ./main_noif.sh
/dev/fd/62 /dev/fd/61
/dev/fd/62 /dev/fd/61
$ ./main_source.sh
/dev/fd/62 /dev/fd/61
/dev/fd/62 /dev/fd/61

==> main.sh <==
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

if [[ x ]]; then
    source <(echo -n)
    function f {
        echo <(echo) <(echo)
    }
    f
    f
fi

==> main_noif.sh <==
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

source <(echo -n)
function f {
    echo <(echo) <(echo)
}
f
f

==> main_source.sh <==
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

if [[ x ]]; then
    function f {
        echo <(echo) <(echo)
    }
    f
    f
fi

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]