rubyinstaller2 icon indicating copy to clipboard operation
rubyinstaller2 copied to clipboard

Unable to run rake: "/c/Ruby25-x64/bin/rake: line 4: {#: command not found"

Open sbonds opened this issue 6 years ago • 7 comments

What problems are you experiencing?

The rake executable won't run, giving the error:

/c/Ruby25-x64/bin/rake: line 4: {#: command not found

Steps to reproduce

  1. Install Git for Windows
  2. Install Ruby 2.5.3-1-x64 with MSYS2
  3. Open Git MINGW64 command window
  4. Run rake

What's the output from ridk version?

$ ridk version
bash: ridk: command not found

:-)

This is probably what you really wanted:

$ ridk.cmd version
---                                                                              
ruby:
  path: C:/Ruby25-x64
  version: 2.5.3
  platform: x64-mingw32
ruby_installer:
  package_version: 2.5.3-1
  git_commit: 16e7aa4
msys2:
  path: C:\Ruby25-x64\msys64
cc: x86_64-w64-mingw32-gcc (Rev1, Built by MSYS2 project) 8.2.1 20181214
sh: GNU bash, version 4.4.23(1)-release (x86_64-pc-msys)
os: Microsoft Windows [Version 10.0.17134.112]

Unsubstantiated Speculation

If I had to guess, I suspect that the MINGW64 shell provided by Git isn't interpreting some of the magic characters at the start of the "rake" binary:

$ head /c/Ruby25-x64/bin/rake
:""||{ ""=> %q<-*- ruby -*-
@"%~dp0ruby" -x "%~f0" %*
@exit /b %ERRORLEVEL%
};{#
bindir="${0%/*}" #
exec "$bindir/ruby" "-x" "$0" "$@" #
>,
}
#!/usr/bin/env ruby
#

Is that the intended start of the rake binary?

Workarounds

Use rake.cmd instead of rake

Use the x64-mingw32 shell included with Ruby

sbonds avatar Feb 08 '19 01:02 sbonds

You're right bash isn't well supported. I focused on CMD and PowerShell so far. It's difficult on Windows to support all of them, since this three types of shells are so very different.

I'll have a look when time permits. If you want to help I'm glad about pull requests. Or if you have some suggestions how to implement better bash support, please feel free to post them here!

larskanis avatar Feb 08 '19 17:02 larskanis

I don't envy you the task of finding a way to have so many different interpreters all work on the same script. If I find a magic solution, I'll come back with a pull request. In the meantime, perhaps this Issue will serve as some useful Google-bait for Future Me or anyone else experiencing the same error message. The workarounds are pretty painless... once they're found.

sbonds avatar Feb 08 '19 18:02 sbonds

On my system, which has a stand-alone MSYS2/MinGW install, I noticed the following:

  1. MSYS2/MinGW shell sets its own path. MSYS2/MinGW has an MSYS2 Ruby package, and it installs the Ruby exe in usr/bin. It is not setup to work with a stand-alone Ruby install.

  2. 'Git Bash' adds to PATH, but does not remove anything (? I think)

  3. The bat/cmd files used in Ruby (rake, gem, etc) can make use of "%~dp0ruby.exe", which allows them to refer to the ruby.exe file in the same folder as the file. This also allows them to be portable.

  4. I'm more Windows type, so I don't often use the MSYS2 or Git shells. But, it's my impression that the shebang line (the bash sctipt line starting with #!) will use an exe in the path if the included absolute path does not exist.

Hence, the existing bash scripts need everything before the shebang line deleted, then the shebang line

#!/usr/bin/env ruby

replaced with the absolute path to the Ruby exe (which should be the same path as the bash script)…

I don't know enough about the installer to know whether it can configure the scripts at install time.

MSP-Greg avatar Feb 08 '19 20:02 MSP-Greg

I'm not sure whether I'll add full bash support and when. But thank you both for sharing your experience!

larskanis avatar Feb 11 '19 06:02 larskanis

I've found that after reinstalling rake with gem install rake, rake works fine from bash, PowerShell, and cmd.

The rake installed by gem starts with #!C:/Ruby26-x64/bin/ruby.exe on my system (which is the correct path, since I'm running Ruby 2.6.5).

zanedp avatar Jan 15 '20 15:01 zanedp

Still happening when using https://github.com/ruby/setup-ruby as part of github actions CI at the moment a separate msys2 installation is installed. When using ridk this doesn’t happen.

/c/hostedtoolcache/windows/Ruby/3.0.0/x64/bin/rake: line 4: {#: command not found

jwillemsen avatar Feb 17 '21 08:02 jwillemsen

Easiest way to suppress this is:

  1. Go to C:/Ruby/YOURVERSION/bin
  2. Edit rake file (without extension)
  3. Add space in 4 line, before hash sign
:""||{ ""=> %q<-*- ruby -*-
@"%~dp0ruby" -x "%~f0" %*
@exit /b %ERRORLEVEL%
};{replaceMeWithSpace#

Credits

writeClearly avatar Apr 24 '21 13:04 writeClearly