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")

Community
  • 1
  • 1
Rose Perrone
  • 61,572
  • 58
  • 208
  • 243
  • 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. – mu is too short Jul 26 '12 at 22:29
  • @muistooshort The [documentation](http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-system) 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.) – Darshan Rivka Whittle Jul 26 '12 at 23:07
  • @DarshanComputing: The `system` docs aren't explicit, they just imply that `/bin/sh` will be used by referring to `exec`. – mu is too short Jul 27 '12 at 02: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 ;) – Darshan Rivka Whittle Jul 27 '12 at 03:25

1 Answers1

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)
Darshan Rivka Whittle
  • 32,989
  • 7
  • 91
  • 109