I am using a dynamically assigned file descriptor in a script as described in this post:
zsh and POSIX equivalent of bash's `{var}>&1`
The script itself is meant to be portable between bash and zsh, so emulate -LR bash is executed early on if the script detects it is being run in zsh.
Unfortunately, this is breaking exec {fd}>&..., which has been supported in zsh and bash for quite some time.
To illustrate, this script succeeds (also works in bash):
#!/usr/bin/env zsh
set -euo pipefail
for i in {1..10}; do
exec {fd}> >( tee /dev/stderr | logger )
echo "FD: ${fd}" >&"${fd}"
done
But this does not:
#!/usr/bin/env zsh
set -euo pipefail
emulate -LR bash
for i in {1..10}; do
exec {fd}> >( tee /dev/stderr | logger )
echo "FD: ${fd}" >&"${fd}"
done
command not found: {fd}
Can anyone point me to a comprehensive list of what emulate -R bash does under the hood (maybe I overlooked it, but I wasn't able to find a real man page for emulate). Or better yet if anyone knows which specific option causes this issue, that would be great.
Thanks in advance for any help.
emulate bash, but serves me right for trusting random blogs. It does seem like it would be a worthwhile zsh feature though as now I will need to piece it together myself. – oO.o Sep 17 '20 at 14:52bashemulation mode has been discussed several times on the zsh mailing lists (from as far back as 2001 AFAICS). – Stéphane Chazelas Sep 17 '20 at 15:50