Reputation: 19
I'm using uname -n
as an example. I've tried other shell commands, using the full pathname to the shell command, and I used other delimiters, such as %x( )
and %x[ ]
.
$ uname -n
my-server
$ which env
/usr/bin/env
$ which ruby
/home/ubuntu/.rvm/rubies/ruby-2.2.1/bin/ruby
$ irb
2.2.1 :001 > %x{uname -n}
=> "my-server\n"
2.2.1 :002 > exit
$ cat ET.rb
#!/usr/bin/env ruby
%x{uname -n}
$ ruby ET.rb
$ ### !!!?!?!? I'm expecting "my-server"
Upvotes: 0
Views: 187
Reputation: 8831
In IRB, it will show the results of any Ruby statements you feed it. But if in a Ruby script, you should use puts
or print
method to print something out:
puts %x{uname -n}
or:
print %x{uname -n}
Upvotes: 1