Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This should be surprisingly simple, but it eludes me. I'm trying to set up a simple command such that I can type: ruby myfile someparams and it will return something via stdio.
I want to include a gem, like https://rubygems.org/gems/github-linguist and pass something to it and see what it has as a response.
I'm a bit lost. Ideas?
Here's a sample script that just echoes its arguments:
#!/usr/bin/env ruby
puts "The arguments were:"
ARGV.each { |curr_arg| puts curr_arg }
Save this to foo.rb, then chmod a+x foo.rb. You can either move it to some location on your PATH, in which case you can just type foo.rb some args from anywhere, or you can run it explicitly from the current directory with either ./foo.rb some args or ruby foo.rb some args.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have two shell script files: "script1.sh" and "script2.sh".
Running "script1.sh" results in echo two strings.(e.g. str1 str2).
I want this "script1.sh" output (str1 and str2) to be used as the input arguments for the 2nd script, "script2.sh".
(i.e. To be equivalent to ./script2.sh str1 str2)
How can I do it?
Thanks.
Try this:
./script1.sh | xargs ./script2.sh.
This will take your output of ./script1.sh (i.e. str1 str2), split it by space and pass it to ./script2.sh as arguments.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to write a function in my bashrc to make executing a python script I wrote easier, along with piping the output. Please see example:
function pythonfunction()
{
script.py $filename | less
}
I'd like the execute the function, referencing a file, i.e.
pythonfunction testfile.txt
Apologies if this is super simple, I can't see to find the answer anywhere..
For reference, I get the error:
ERROR: Unknown Option: testfile.txt
Many Thanks,
You want this:
function pythonfunction()
{
script.py "$1" | less
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can I make calls to the command line using the back tick and variables? Something like:
myvar = "C:\Program Files"
`cd ` + myvar
Also, consider using a system() call, for clarity. Backticks are for short commands.
system allows for a visually-more-obvious open + close block formatting that befits large, or multi-line OS instructions.
See this SO Q+A
Though, if you're writing large OS scripts, put them in a shell file, check it into VCS, and exec that with a ruby one-liner.
Try this:
`cd "#{myvar}"`
Example:
$ irb --simple-prompt
>> `pwd`
=> "/home/kirti\n"
>> var = 'ruby'
=> "ruby"
>> `cd "#{var}" && pwd`
=> "/home/kirti/ruby\n"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I wont write some script in Ruby on Linux server. I need statistic from server and I'm a beginner in Ruby.
I have problem with Linux commands, because if I use exec to use Linux command, my program is fallen without error.
disks = ["sda", "sdb"]
Code:
disks.each do |disk|
puts "disk test start"
exec "smartctl -a /dev/#{disk} > /tmp/sestavy/#{disk}"
puts "disk test end"
end
Output:
[root#banan sestavy]# ruby test.rb
disk test start
[root#banan sestavy]#
Thanks
Honza
That's just what exec does: it replaces the currently running program with a new one. This is not specific to Ruby, it works the same way in the shell, in C, in pretty much any other environment.
When you use exec, it replaces the current process with what you want to execute. So it won't return to your Ruby script. See this explanation for different methods for shell execution.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'd like to make a bash function (or alias) like:
function warmup() { ab -n100 http://$1.myapp.appspot.com/ ;}
But I get:
$ warmup some_version
ab -n 1000 -c 5 http://.myapp.appspot.com/ some_version
What am I doing wrong? Is this possible?
It works for me in bash 4.2.10, it might not work on an older version. Try upgrading yours.