9 Replies - 1367 Views - Last Post: 10 August 2016 - 05:13 PM Rate Topic: -----

#1 AmericanPi  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 14
  • Joined: 30-July 16

Do I HAVE to type ruby first?

Posted 07 August 2016 - 01:43 PM

I have to type ruby before and file name if i want to run a code in the command prompt on my mint18 machine.

Can anyone give me a workaround? I don't want to have to type ruby every time i run a program.

tx

Is This A Good Question/Topic? 0
  • +

Replies To: Do I HAVE to type ruby first?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13488
  • View blog
  • Posts: 53,864
  • Joined: 12-June 08

Re: Do I HAVE to type ruby first?

Posted 07 August 2016 - 01:46 PM

How else are you going to let the terminal know that you want to run a ruby script? It won't automagically know.
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2330
  • View blog
  • Posts: 9,381
  • Joined: 03-December 12

Re: Do I HAVE to type ruby first?

Posted 07 August 2016 - 01:46 PM

That is how it works, you pass what interpreter to use and the file as the argument.
Was This Post Helpful? 1
  • +
  • -

#4 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6377
  • View blog
  • Posts: 25,768
  • Joined: 12-December 12

Re: Do I HAVE to type ruby first?

Posted 07 August 2016 - 01:49 PM

If you want to create an executable file then search "ruby create executable file". E.g.

RubyScript2Exe
Was This Post Helpful? 1
  • +
  • -

#5 xclite  Icon User is offline

  • I wrote you an code
  • member icon


Reputation: 1237
  • View blog
  • Posts: 4,029
  • Joined: 12-May 09

Re: Do I HAVE to type ruby first?

Posted 07 August 2016 - 02:24 PM

There is a standard way of doing this for one-off scripts.

First, put a shebang in as the first line of the script:
#!/usr/bin/ruby
puts "hello"



Next, mark the file as executable:
chmod +x test.rb



Finally, run it:
./test.rb



The shebang tells a unix-like system where to find the interpreter for this scripting language. It should be the path to your Ruby interpreter, which may vary. Many people use /usr/bin/env ruby.

I'd encourage you to do more reading about shebangs if you plan to use them, and this isn't a useful strategy for making all ruby programs executable.
Was This Post Helpful? 2
  • +
  • -

#6 AmericanPi  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 14
  • Joined: 30-July 16

Re: Do I HAVE to type ruby first?

Posted 08 August 2016 - 05:25 PM

[fonts="Lucida Console][size=4]

tx everyone.

no big deal i guess. i def see how #! and .exe stuff could compliment some off my projects.

@modi123_1 Guess my windows machines must "automagically" know then.

tx again evry1
Was This Post Helpful? 0
  • +
  • -

#7 xclite  Icon User is offline

  • I wrote you an code
  • member icon


Reputation: 1237
  • View blog
  • Posts: 4,029
  • Joined: 12-May 09

Re: Do I HAVE to type ruby first?

Posted 08 August 2016 - 06:00 PM

Windows actually has a way of associating extensions with programs. Back when I developed Ruby on Windows, during installing it would associate "*.rb" with the Ruby interpreter, so that when I ran them it would know what to run them on.
Was This Post Helpful? 1
  • +
  • -

#8 AmericanPi  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 14
  • Joined: 30-July 16

Re: Do I HAVE to type ruby first?

Posted 08 August 2016 - 06:11 PM


right. i could see that.

what was that line of code you threw in there? something about association in windows?

lol,,,


didnt mean to lol u.
don't know how to edit my posts.
Was This Post Helpful? 0
  • +
  • -

#9 xclite  Icon User is offline

  • I wrote you an code
  • member icon


Reputation: 1237
  • View blog
  • Posts: 4,029
  • Joined: 12-May 09

Re: Do I HAVE to type ruby first?

Posted 08 August 2016 - 06:12 PM

The windows bit was done via a graphical interface on Windows or by the installer - the line of code is for Unix-like systems. See this question for Windows:
http://stackoverflow...y-just-its-name
Was This Post Helpful? 1
  • +
  • -

#10 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 1377
  • View blog
  • Posts: 4,316
  • Joined: 20-March 10

Re: Do I HAVE to type ruby first?

Posted 10 August 2016 - 05:13 PM

Yes there is a tick box which lets you set some environment variables,

namely PATH and PATHEXT.

PATHEXT is a windows environment variable that associates file extensions that are executable from every command line.

Regards

Snoopy.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1