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

  • Home
  • SEARCH
  • 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 6731299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:30:43+00:00 2026-05-26T10:30:43+00:00

I am using a bash script to launch a ruby script. this works very

  • 0

I am using a bash script to launch a ruby script.
this works very well if you are in the sir of the script but if you are not in that dir the script acts funny because it is not on the file path.

#!/bin/sh
jruby -Ilib script.rb $@

I added this to the script.

mypath=`realpath $0`

cd `dirname $mypath`/..

It makes the script run from any place I want. the problem is that its arguments do not get their relative path names changed.

I am using trollop for my input parsing.

My question is: How can I change the input of the path in the input so it will be the correct relative path when I push the args to the ruby script.
I would be happy with a ruby fix to this problem.

  • 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-05-26T10:30:43+00:00Added an answer on May 26, 2026 at 10:30 am

    This uses bash specifically. It assembles an array of the arguments, calling realpath for each.

    #!/bin/bash
    mypath=$(realpath $0)
    args=()
    for arg; do
      args+=( "$(realpath "$arg")" )
    done
    cd "$(dirname "$mypath")"/..
    
    jruby -Ilib script.rb "${args[@]}"
    

    I’ve liberally sprinkled double quotes throughout the script to handle files and paths that contain spaces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml file that I want to configure using a bash script.
In a bash script, I'm using wine to call a DOS program that requires
I'm using a bash script with display command, after upgrading to Ubuntu 10.10 this
I'm creating a bash script that will load CSV files using SQL*Loader. Please refer
I have a Ruby script that produces a Latex document using an erb template.
I am working on a bash script using sed and cut that will take
I'm trying to run a bash script using shell_exec but It doesnt seem to
I'm using a bash script to automate a set of tests for some other
In Bash script, what is the difference between the following snippets? 1) Using single
Im writing a bash-script to perform an offsite backup, using rsync over SSH. I'm

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.