0

I need to run some commands within a Ruby file, but rather than running them in Bash, because I'm on Unix, I want to run them in a different shell, called "s3sh". How can I specify the shell?

For example, in my Ruby code, I tried:

 system "export RUBYSHELL=s3sh"
 s3 = system "RightAws::S3Interface.new(#{S3ID}, #{S3KEY})"
 system "s3.copy(#{SRCBUCKET}, #{FILE}, #{DESTBUCKET}, #{FILE})"
 system "unset RUBYSHELL"

but it's not possible export environment variables to the shell the Ruby script runs in. (see "Exporting an Environment Variable in Ruby")

4
  • I'm pretty sure system always uses /bin/sh on Unixy systems so you might have to invoke s3sh by hand and feed it the necessary commands on its STDIN. Commented Jul 26, 2012 at 22:29
  • @muistooshort The documentation specifically says so (that system() always uses the standard shell, which is always /bin/sh on Unix-like systems) so you're correct. (Although things happen to be easier in this case.) Commented Jul 26, 2012 at 23:07
  • @DarshanComputing: The system docs aren't explicit, they just imply that /bin/sh will be used by referring to exec. Commented Jul 27, 2012 at 2:02
  • @muistooshort Huh, seems explicit to me: "command line string which is passed to the standard shell", "See Kernel.exec for the standard shell", and "The standard shell means always /bin/sh on Unix-like systems". Not really worth debating though, we both think you're correct and only disagree in how certain we are that you're correct ;) Commented Jul 27, 2012 at 3:25

1 Answer 1

2

s3sh is just a wrapper around the AWS::S3 gem, so you're over-complicating things. You don't need to shell out; you can just use Ruby:

require 'right_aws'

s3 = RightAws::S3Interface.new(S3ID, S3KEY)
s3.copy(SRCBUCKET, FILE, DESTBUCKET, FILE)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.