-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Warn on ambiguous redirect #1136
Comments
Since the parameters are not in order you will get an error ofc. |
Not with bash 4.4, it just works |
No it wont work since your example is wrong. |
Unless --long-argument2 takes two parameters. |
It does work on bash-4.4, the shell will pass the parameters to the command, as one would not expect. This is why I am suggesting that shellcheck warn on this, it's just confusing. param1 param2 may just be parameters, like |
Ah, beats me. Yeah that is indeed ambiguous. |
For added ambiguous-ness #!/bin/bash
> file.txt echo foo bar baz Will result in |
This behavior is POSIX and supported by all bash versions. "Ambiguous redirect" is instead the error you get when you redirect to a word that becomes more than one due to globbing or wordsplitting:
ShellCheck already warns about quoting, but it doesn't warn against redirecting to globs, which it really should. I'm not so sure about a general warning about not having redirections last though. Things like |
I'm in favor of "redirections last" a large amount of shellcheck is already about making valid code legible / sane and redirects anywhere but last are bad IMO...I'm also in favor of conditions first (in crazy languages that support "x... if y") |
Older versions of bash error out with an ambiguous redirect (ie parameters passed after redirect). Newer versions of bash apparently accept it, and just pass the args to the command.
Here's a snippet or screenshot that shows the problem:
This also works in newer bash versions (!?!)
The file will contain "one two three four"
Both of these are just confusing and should be warned about.
Here's what shellcheck currently says:
$ shellcheck myscript
No issues detected!
Here's what I wanted or expected to see:
warn about an ambiguous redirect
The text was updated successfully, but these errors were encountered: