Skip to content

Instantly share code, notes, and snippets.

@anil826
Last active March 28, 2016 05:25
Show Gist options
  • Save anil826/95810de003c90132f064 to your computer and use it in GitHub Desktop.
Save anil826/95810de003c90132f064 to your computer and use it in GitHub Desktop.
Shell scripting in ruby
#!/usr/bin/ruby -w
#system('ls -la') #=> outputs the output of that command
#system('skype') #open skype using system command.
#http://www.dreamsyssoft.com/ruby-scripting-tutorial/loops-tutorial.php
require 'optparse'
options = {:name => nil, :age => nil}
parser = OptionParser.new do|opts|
opts.banner = "Usage: ruby_linux.rb [options]"
opts.on('-n', '--name name', 'Name') do |name|
options[:name] = name;
end
opts.on('-a', '--age age', 'Age') do |age|
options[:age] = age;
end
opts.on('-h', '--help', 'Displays Help') do
puts opts
exit
end
end
parser.parse!
if options[:name] == nil
print 'Enter Name: '
options[:name] = gets.chomp
end
if options[:age] == nil
print 'Enter Age: '
options[:age] = gets.chomp
end
sayHello = 'Hello ' + options[:name] + ', '
if Integer(options[:age]) == 100
sayAge = 'You are already 100 years old!'
elsif Integer(options[:age]) < 100
sayAge = 'You will be 100 in ' + String(100 - Integer(options[:age])) + ' years!'
else
sayAge = 'You turned 100 ' + String(Integer(options[:age]) - 100) + ' years ago!'
end
puts sayHello + sayAge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment