2

I'm trying to use shebang with /usr/bin/env form to execute my script under custom interpret. This is how my file looks:

$ cat test.rb 
#!/usr/bin/env winruby

print "Input someting: "
puts "Got: #{gets}"
sleep(100)

but it fails when executed:

$ ./test.rb 
/usr/bin/env: ‘winruby’: No such file or directory

and I do not understand why

tv185035@WCZTV185035-001 ~
$ winruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x64-mingw32]

tv185035@WCZTV185035-001 ~
$ env winruby --version
env: ‘winruby’: No such file or directory

tv185035@WCZTV185035-001 ~
$ which winruby
/home/tv185035/bin/winruby

The winruby exists, is in path and is executable. But env fails to find it. I took a look at man env but it didn't tell me anything useful.

EDIT:

$ cat ~/bin/winruby 
#!/usr/bin/bash

winpty /cygdrive/g/WS/progs/Ruby25-x64/bin/ruby.exe "$@"
  • What is the output of type winruby ? – Mark Plotnick Apr 24 '18 at 10:05
  • winruby is hashed (/home/tv185035/bin/winruby) – graywolf Apr 24 '18 at 10:27
  • Does cd; sh -c winruby succeed when typed to an interactive sgell? – Mark Plotnick Apr 24 '18 at 12:48
  • It does not (sh: winruby: command not found), what does that tell me? :) – graywolf Apr 24 '18 at 15:34
  • Maybe your PATH isn't exported? Try export PATH, then try the env and sh -c commands again. – Mark Plotnick Apr 24 '18 at 15:46
1

If the output of

echo 1l|ed test.rb

ends with \r$ you have a <carriage return> in front of the <line-feed>

Lines in unix are line-feed terminated, so env looks for the 'winruby\r' and not 'winruby'.

edit your script in the unix environment with either vi , ed or nano and remove the '\r' from the end of the line.

Edit:

I can create the same outcome as you, when my PATH is set, but not set to be exported.

# PATH is set but not exported
jo@hostname:~/tmp$ winruby --version
running winruby --version
jo@hostname:~/tmp$ env winruby --version
env: winruby: No such file or directory

# print variables starting with PATH
jo@hostname:~/tmp$ set |grep -e ^PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/jo/tmp/bin

# print exported variables starting with PATH
jo@hostname:~/tmp$ env | grep -e ^PATH

# Oops ! nothing, so exporting PATH
jo@hostname:~/tmp$ export PATH
jo@hostname:~/tmp$ env | grep -e ^PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/jo/tmp/bin

# Final check
jo@hostname:~/tmp$ env winruby --version
running winruby --version
  • You are correct, I hadn't seen that section. I'll leave this answer standing though, since it might help to look for the <cr><lf> vs <lf> issue. What is winruby a windows script to start ruby ? I wonder what that looks like inside. – X Tian Apr 24 '18 at 11:06
  • I've added cat ~/bin/winruby to the question; basically just forward all arguments to windows ruby executable wrapped in winpty – graywolf Apr 24 '18 at 11:22
  • Does cat -vet ~/bin/winruby | head -1 show any stray characters? – Mark Plotnick Apr 24 '18 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.