Closed tandy-1000 closed 1 year ago
What did you run exactly?. It's likely that you're trying to use POSIX mode when &>
is bash syntax. Unfortunately, &>
is also valid POSIX syntax; it just parses as & >
, i.e. "background command then start a redirection".
Just noticed today
if ping -c 1 $default_gateway_ip &>/dev/null; then
becomes
if
ping -c 1 $default_gateway_ip &
>/dev/null
then
Using https://marketplace.visualstudio.com/items?itemName=mkhl.shfmt
The "fix" above is to give a helpful error, since I suspect that both of you were using POSIX mode to try to parse Bash syntax. You should be using the Bash mode, which should kick in automatically if your shell script has a .bash
extension or a shebang like #!/usr/bin/bash
. More details in the commit above.
When shfmt sees a
&>
, it is broken onto a new line:Becomes:
The transformation also breaks the code.
If you switch
&>
with>&
this does not happen.