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

$'\r': command not found #5032

Closed
lopatnov opened this issue Mar 31, 2020 · 7 comments
Closed

$'\r': command not found #5032

lopatnov opened this issue Mar 31, 2020 · 7 comments

Comments

@lopatnov
Copy link

Dear WSL team,

I have an issue with /bin/bash because there are a lot of scripts with /r/n line endings. The bash tool recognizes \r\n line ending as unknown command of \r symbol. This symbol users even can't see in normal bash code editors. This might be a bug, because DOS uses carriage return and line feed ("\r\n") as a line ending, which Unix uses just line feed ("\n").

Please, add a feature to recognize line endings for bash tool of WSL.

@therealkenc
Copy link
Collaborator

GNU bash is not a "tool of WSL", and this behavior is by-design bash. /dupe #2365 et al. It would still be interesting to see if someone motivated could get set -o igncr upstreamed (message), or failing that, create a Launchpad PPA.

@ghost
Copy link

ghost commented Mar 31, 2020

Hi! We've identified this issue as a duplicate of another one that already exists in this repository. This specific instance is being closed in favor of tracking the concern over on the referenced thread.

Thanks for your report!

@ghost ghost added the duplicate label Mar 31, 2020
@lopatnov
Copy link
Author

lopatnov commented Apr 3, 2020

Ok, and when bash will support Windows line endings?

@therealkenc
Copy link
Collaborator

Ok, and when bash will support Windows line endings?

GNU bash? Wrong place to ask; no one here would know the answer to a "when" question regarding an independent software project.

Guessing (and I do have to guess) short answer is probably (to a first order) "never". Reasoning being: (a) It is valid to have '\r' in a bash script by design, (b) Cygwin has been around for a quarter century and the patch was never upstreamed, (c) It has been two years since #2318 was posted, and no one has wanted it bad enough to ask the bash maintainers if they would be amenable to accepting the feature upstream, and, (d) There is a straightforward solution (use *nix line-endings) that transcends WSL becoming a thing.

An alternate "when" answer would be: Moments after anyone motivated creates a Launchpad PPA with the set -o igncr patch applied. Even sooner if you compile bash with the patch applied yourself. Bonne chance.

@andrew-aladev
Copy link

andrew-aladev commented Apr 28, 2021

Ok, and when bash will support Windows line endings?

cygwin developers doesn't really care about users, please use msys2 and mingw where possible instead. I am sure that cygwin will never implement this feature.

@therealkenc
Copy link
Collaborator

cygwin will never implement this feature.

The igncr extension is a cygwin patch since the olden tymes (circa 1990s).

@andrew-aladev
Copy link

andrew-aladev commented Apr 28, 2021

I've removed previous comment, because provided wrong patch, sorry.

The igncr extension is a cygwin patch since the olden tymes (circa 1990s).

This patch is wrong from design perspective. igncr, ignbrk, etc are just input modes. SHELLOPTS includes options for shell script business logic only, input mode should not be a part of shell opts. Shell opts are readonly for current local script, user can setup local shell options that won't be passed by default to siblings, user can manually pass shell opts for scripts subtree.

For example you want to ignore cr, you are using the following command: cygwin\bin\bash -o igncr script.sh. Your local myscript.sh is the following:

#!/bin/bash
./subscript.sh

subscript.sh is the following:

#!/bin/bash
./script.sh

script.sh is the following:

#!/bin/bash
echo "fit"

myscript.sh will fail because subscript.sh will fail: -o igncr is local option for myscript.sh only and won't be passed to subscript.sh or script.sh. -o igncr as command line bash parameter or set -o igncr is just absurd: you are declaring that your local script may use cr, but not care about sibling scripts. That's why people are poisoning all its scripts with:

(set -o igncr) 2>/dev/null && set -o igncr

This line is awful, but today it is used inside millions of bash scripts. Bash >= 3.2 added ability to pass env SHELLOPTS=igncr globally before script execution and igncr will be passed to any subscript, but ... igncr is not default option and won't be used in cygwin by default!

igncr in cygwin not default

That's why I am talking about cygwin developers don't care about users, they are care only about its standards. What does it mean standards in cygwin? They made a mistake, placed input mode inside shell options and they will carry this mistake with heads held high through the centuries. They will torture users as long as possible, they will never made default windows input mode actually as default input mode for bash.

So please use msys2 and mingw where possible, its developers cares about users, they maintain proper patch for bash. This patch just removes carriage return and it is simple and stable, your bash script just works as expected in msys2 on windows.

Related to issue.

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

No branches or pull requests

3 participants