Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected reformatting of multi-line commands #1045

Open
AxelKrypton opened this issue Nov 22, 2023 · 1 comment
Open

Unexpected reformatting of multi-line commands #1045

AxelKrypton opened this issue Nov 22, 2023 · 1 comment

Comments

@AxelKrypton
Copy link

A bash command split on multiple lines without a space before \ gets reformatted.

$ printf 'my_command\\\n    split\n'
my_command\
    split
$ shfmt -ln bash -i 4 < <(printf 'my_command\\\n    split\n')
my_command split
$ shfmt -ln bash -i 4 < <(printf 'my_command \\\n    split\n')
my_command \
    split

I am not sure whether this is an expected behaviour, but I was surely surprised by this. I also did not find an answer in existing issues or discussions.

To give some context, I read about the (many) discussions asking for having a maximum length option (e.g. #80). In projects where there is a maximum line length enforcement, we split lines by hand using \ and I'd like shfmt not to change that, especially because then lines would often exceed the maximum length.

Is this behaviour intended?

@AxelKrypton
Copy link
Author

In the description above my_command was e.g. any possible user function. For some builtins like printf the behaviour is different1.

$ shfmt -ln bash -i 4 < <(printf '%s\\\n    %s\n' "printf '%s\n'" 'My string')
printf '%s\n' \
    My string
$ shfmt -ln bash -i 4 < <(printf '%s \\\n    %s\n' "printf '%s\n'" 'My string')
printf '%s\n' \
    My string

Maybe someone can shed some light on this. It might well be that I am missing something here. 🤔

1Sorry for the process substitution brain-gymnastic, it is definitely not something I would use in a real script, but it was the most compact way to offer something to play with in a terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant