1. Tech

Your suggestion is on its way!

An email with a link to:

http://linux.about.com/library/bl/open/newbie/blnewbie7.2ruby.htm

was emailed to:

Thanks for sharing About.com with others!

7.2 Simple Programming under Linux
Learn advanced Linux commands
 
 Related Resources
• Linux Newbie Administrator Guide
• 0. Linux Benefit
• 1. Before Installation
• 2. Linux Resources/Help
• 3. Basic Operations FAQ
• 4. Newbie Admin FAQ
• ~ 4.1 Lilo
• ~ 4.2 Drives
• ~ 4.3 X-Windows
• ~ 4.4 Configurations
• ~ 4.5 Networking
5. Shortcuts / Commands
• 6. Linux Applications
• 7. Learn Linux Commands
• A. How to Upgrade Kernel?
 

ruby

A purely object-oriented scripting language. This language is a relative newcomer, but it is rapidly gaining popularity, and may well be the flavour of the future of programming.

To write a simple program in ruby, I open my favorite text editor and start a program with the following first line:
#!/usr/bin/ruby

Here is an example of a program that I wrote to help me understand the basics of the ruby language:

#!/usr/bin/ruby
#This is a comment
 a = Array.new
 print "Please enter a few words (type EXIT to stop):\n"

 i = 0
 while enterWord = STDIN.gets
   enterWord.chop!
   if enterWord == "EXIT"
     break
   end
   a[i] = enterWord
   i += 1
 end

#sort the array
for i in 0...a.length-1 do
  for j in i+1...a.length do
    if a[j] < a[i]
      tmp = a[i]
      a[i] = a[j]
      a[j] = tmp
    end
  end
end

#Output the results
print "You entered "  + a.length.to_s + " entries.\n\n"
for i in 0...a.length do
  print "Entry " + (i+1).to_s + ": "+ a[i] + "\n"
end

I save my ruby script to file "myprogram". To execute it, I need to type on the command line:
./myprogram

Next > Back to "Learn Linux Commands"

Can't find what you are looking for?
Search the

Stay up-to-date!
Subscribe to the Linux free newsletter.

You can opt-out at any time. Please refer to our privacy policy for contact information.

Discuss in my forum

©2014 About.com. All rights reserved.