koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.22k stars 1.77k forks source link

In POSIX sh, >& is undefined when using variables representing file descriptors #1515

Open Earnestly opened 5 years ago

Earnestly commented 5 years ago

For bugs

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:


#!/bin/sh
fd=3
exec 3>&1
printf 'test\n' >&"$fd"

Here's what shellcheck currently says:

In t.sh line 4:
printf 'test\n' >&"$fd"
                ^-----^ SC2039: In POSIX sh, >& is undefined.

For more information:
  https://www.shellcheck.net/wiki/SC2039 -- In POSIX sh, >& is undefined.

Here's what I wanted or expected to see:

Nothing.

ghost commented 3 years ago

I just ran into this issue as well.