Skip to content

BUG: Invalid formatting for shell syntax for closing file descriptors #1127

Open
@titaniumtraveler

Description

When trying to format shell script containing the bash syntax for closing a file
descriptor, shfmt inserts a space between the variable part and the redirector
part.

Running

echo 'exec {variable_name[1]}<&-' | shfmt -ln=bash --diff

results in

diff <standard input>.orig <standard input>
--- <standard input>.orig
+++ <standard input>
@@ -1,1 +1,1 @@
-exec {variable_name[1]}<&-
+exec {variable_name[1]} <&-

which is invalid bash syntax.

See this sentence from REDIRECTIONS from man bash(1)

If >&- or <&- is preceded by {varname}, the value of varname defines the file descriptor to close.

$ shfmt --version
v3.10.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions