Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:58:13+00:00 2026-06-17T18:58:13+00:00

Ruby seems to use /bin/sh as the shell interpreter, which on a *nix machine

  • 0

Ruby seems to use /bin/sh as the shell interpreter, which on a *nix machine doesn’t understand /bin/bash commands such as pushd. This is what irb tells me:

1.9.3-p327 :011 > `pushd /tmp; echo foo`
sh: 1: pushd: not found
=> "foo\n"

On OSX, /bin/sh is an alias for bash, so the above snippet runs fine there. Is there a way to force Ruby on a *nix machine to use /bin/bash for interpreting shell commands?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:58:14+00:00Added an answer on June 17, 2026 at 6:58 pm

    Using Bash commands like pushd in Ruby is pointless, because those commands affect Bash’s internal state of the Bash interpreter, and when you Run a shell command from Ruby using backticks or system, it creates a new subprocess, runs the command, and then closes that subprocess.

    That means that even if you somehow manage to run pushd as a Bash command from Ruby, what will happen is that the the Bash subprocess will start, push the directory to the directory stack, and then exit. The changes you’ve made to the directory stack will be erased with all the other subprocess’ data – and the next time you use a shell command you won’t be at that directory.

    You are scripting in Ruby, not in Bash – internal Bash commands have no meaning here, so you need to use the Ruby equivalents. For example, instead of writing:

    system 'pushd /tmp'
    system 'touch file_in_tmp'
    system 'popd'
    

    Which wouldn’t work, what you want to do is:

    Dir.chdir '/tmp' do
        system 'touch file_in_tmp'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new with ruby and I can't understand one thing. When I use
TLDR: How do I force a rails app to use the correct ruby interpreter?
Sam Ruby, author of RESTful Web Services seems to come out against the use
I've tried many solutions but nothing seems to work! I use Ruby 1.9.3 and
In every benchmark that I found on the web it seems that Ruby is
I tried to install Ruby 1.9.3 using RVM. It seems that it installed without
I would like to step through Ruby code at runtime, but it seems difficult
I am trying to install the cairo ruby gem on OSX 10.6. There seems
does FastCGI work well with PHP? It seems that some people running Ruby on
Ruby doesn't seem to have a facility for defining a protected/private block like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.