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
syntax: redirect operators without spaces can confuse the parser #369
Comments
Sorry for nothing, found my problem. |
Sorry, what was the problem? I started investigating just now, as it turns out. |
--- if-while-fi-old.sh 2019-03-15 14:58:37.718619000 +0100
+++ if-while-fi.sh 2019-03-15 14:54:07.073654000 +0100
@@ -4,7 +4,7 @@
echo "test if-fi"
while read _arg; do
echo "a: ${_arg}"
- done<<DONE
+ done <<DONE
aaa
bbb
ccc |
Thanks. I still think there's a parser bug here; if bash and all other shells accept the original program, but Smaller repro:
|
Even smaller:
|
found another one, not sure it is related, I can open a new issue if you think it's not the same bug: #!/bin/sh
# incorrect redirection to stderr, has to be at the end of the command
echo 1>&2 "stderr"
# incorrect redirection to stderr, has to be at the end of the command
echo -n 1>&2 "stderr" result with #!/bin/sh
# incorrect redirection to stderr, has to be at the end of the command
echo 1>&2 "stderr"
# incorrect redirection to stderr, has to be at the end of the command
echo -n "stderr" 1>&2 expected: #!/bin/sh
# incorrect redirection to stderr, has to be at the end of the command
echo "stderr" 1>&2
# incorrect redirection to stderr, has to be at the end of the command
echo -n "stderr" 1>&2 new bug ? |
Ah, that's not a bug; redirections are allowed either at the end, or after the first argument of a command. This is because some people prefer the I can see this is a bit confusing with |
I've fixed the original bug in the master branch. It's easy to work around, and the canonical format keeps a space anyway, so I'm not going to backport this fix into a stable release for now. |
the redirect operator for a standard stream redirection to another stream has to be at the end of a command:
and it's also true for:
|
Sorry, I'm not sure I follow. The first example you posted in this last comment does redirect to stderr properly for me on Bash:
|
but not in POSIX sh, |
I've tried If you think this is how POSIX shell should behave, could you quote a document like http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html? |
#!/bin/sh
set -v
echo 1>&2 "stderr" >stdout 2>stderr
cat stdout
cat stderr
echo "stderr" >stdout 2>stderr 1>&2
cat stdout
cat stderr This script outputs:
|
Right; it seems like what matters is the order of the redirections. I'm not sure what point you're trying to make; In other words, can |
What I just know is that this script shell only correctly output to stderr when the |
I don't think it's related to the fixed bug. Feel free to open a new issue if there's something you think |
I'm not sure that's a real issue or not since I'm not sure it's correct to write shell script that way, although it works perfectly.
This script can be formatted:
result:
but this one cannot:
result:
I'm using shfmt on FreeBSD:
The text was updated successfully, but these errors were encountered: