Re: Another confusing error from someone else's Cygwin setup
Greetings, David Karr! > I'm seeing a problem with someone else's Cygwin setup, sort of similar to a > problem I asked about a couple of weeks ago, in that it's a problem with > the same user, but seemingly a completely different problem. > He is using a Bash script that I wrote, and he gets a seemingly nonsensical > error that I don't understand. > The script starts out pretty simply, just like this: > -- > #! /bin/bash > #set -x > main() { > if [ "$1" == "" ]; then > usage; > exit; > fi > ... > - > He was getting a weird error on line 3, just saying this: > - > ...: line 3: syntax error near unexpected token `$'{\r'' > ...: line 3: `main() { > --- Quick and dirty way to solve your issue - $ tr -d '\r' > script.fixed < script.erring > This was pretty perplexing, It is actually pretty clear, though. $ od -t x1a < script.erring See the output. -- With best regards, Andrey Repin Wednesday, July 5, 2023 22:22:57 Sorry for my terrible english... -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation:https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
Re: Another confusing error from someone else's Cygwin setup
The line endings were the issue, thanks. They were that way because I didn't realize I should force those files in git to have eol=lf in a .gitattributes file. This is now all fixed. On Mon, Jun 26, 2023 at 7:08 PM Mike Gran wrote: > > On Monday, June 26, 2023 at 04:36:30 PM PDT, David Karr via Cygwin < > cygwin@cygwin.com> wrote: > > > m seeing a problem with someone else's Cygwin setup, sort of similar to a > > problem I asked about a couple of weeks ago, in that it's a problem with > > the same user, but seemingly a completely different problem. > > ... > > > He was getting a weird error on line 3, just saying this: > > - > > ...: line 3: syntax error near unexpected token `$'{\r'' > > ...: line 3: `main() { > > --- > > If you run bash with the "-o igncr" option, it will ignore extraneous > carriage return characters. > > But the characters are there in the first place because your > script has been converted into using Windows line endings: > carriage return + linefeed. > > You didn't say how the script was transferred, but lots > of programs could add returns when you transfer something > to windows: git or ftp just to name a few. > > You both could try running "bash --version". The first line should > say something like > "GNU bash, version 5.2.15(3)-release (x86_64-pc-cygwin)" > > Note the "pc-cygwin" at the end. > > HTH, > Mike Gran > -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation:https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
Re: Another confusing error from someone else's Cygwin setup
> On Monday, June 26, 2023 at 04:36:30 PM PDT, David Karr via Cygwin > wrote: > m seeing a problem with someone else's Cygwin setup, sort of similar to a > problem I asked about a couple of weeks ago, in that it's a problem with > the same user, but seemingly a completely different problem. ... > He was getting a weird error on line 3, just saying this: > - > ...: line 3: syntax error near unexpected token `$'{\r'' > ...: line 3: `main() { > --- If you run bash with the "-o igncr" option, it will ignore extraneous carriage return characters. But the characters are there in the first place because your script has been converted into using Windows line endings: carriage return + linefeed. You didn't say how the script was transferred, but lots of programs could add returns when you transfer something to windows: git or ftp just to name a few. You both could try running "bash --version". The first line should say something like "GNU bash, version 5.2.15(3)-release (x86_64-pc-cygwin)" Note the "pc-cygwin" at the end. HTH, Mike Gran -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation:https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
Re: Another confusing error from someone else's Cygwin setup
On 6/26/2023 4:58 PM, Dan Harkless via Cygwin wrote: On 6/26/2023 4:35 PM, David Karr via Cygwin wrote: > > He was getting a weird error on line 3, just saying this: > > - > > ...: line 3: syntax error near unexpected token `$'{\r'' > > ...: line 3: `main() { > > --- Apologies, I don't remember your other report, but this one kind of sounds like an end-of-line characters problem. Try installing (Cygwin's) dos2unix, if you don't already have it, then try running dos2unix on the script. If it still doesn't work, try then running unix2dos. If you have binutils installed, you can also use the 'file' command for a quick report on whether files have lines terminated with CR (macOS), CRLF (Windows), or LF (UNIX/Linux). 'file' might not realize when you have files with inconsistent line-terminators, though. And I forgot dos2unix also includes a 'mac2unix' command these days (though not a mac2dos), so maybe try that first. -- Dan Harkless http://harkless.org/dan/ -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation:https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
Re: Another confusing error from someone else's Cygwin setup
On 6/26/2023 4:35 PM, David Karr via Cygwin wrote: > He was getting a weird error on line 3, just saying this: > - > ...: line 3: syntax error near unexpected token `$'{\r'' > ...: line 3: `main() { > --- Apologies, I don't remember your other report, but this one kind of sounds like an end-of-line characters problem. Try installing (Cygwin's) dos2unix, if you don't already have it, then try running dos2unix on the script. If it still doesn't work, try then running unix2dos. If you have binutils installed, you can also use the 'file' command for a quick report on whether files have lines terminated with CR (macOS), CRLF (Windows), or LF (UNIX/Linux). 'file' might not realize when you have files with inconsistent line-terminators, though. -- Dan Harkless http://harkless.org/dan/ -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation:https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple
Another confusing error from someone else's Cygwin setup
I'm seeing a problem with someone else's Cygwin setup, sort of similar to a problem I asked about a couple of weeks ago, in that it's a problem with the same user, but seemingly a completely different problem. He is using a Bash script that I wrote, and he gets a seemingly nonsensical error that I don't understand. The script starts out pretty simply, just like this: -- #! /bin/bash #set -x main() { if [ "$1" == "" ]; then usage; exit; fi ... - He was getting a weird error on line 3, just saying this: - ...: line 3: syntax error near unexpected token `$'{\r'' ...: line 3: `main() { --- This was pretty perplexing, so I asked him to uncomment the "set -x" line to see if that provided any useful information, and that fails with a different error: --- : invalid option...: line 2: set: - set: usage: set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...] -- This also makes no sense to me. I compared our "uname -a" outputs, and they are almost identical. However, I then had him run "bash --version", and I compared it to mine. Ironically, I'm using an OLDER version of bash than he is. I'm on v4.4.12(3)-release, and he's on v5.2.15(3)-release. Is there something in 5.x versions of Bash that could cause these issues? -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation:https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple