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 8286941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:54:33+00:00 2026-06-08T11:54:33+00:00

I have a environment config file where i have defined the environment variables. I

  • 0

I have a environment config file where i have defined the environment variables. I use source to get these variables inside my shell script(bash).

I use a checkout command in my shell script which checks out the files from location defined in an environment variable. Now i need to use multiple locations to checkout the files which can be any number for different run of shell script.

For eg. User gives two paths, PATH1 and PATH2 in config file and a NUM_OF_PATHS as 2.

In my shell script I want to do something like below for using path.

i=0
echo ${NUM_OF_PATHS}
while [ $i -lt ${NUM_OF_PATHS} ]
do
    checkout $PATH{$i}
    i=`expr $i + 1`
done

How can I use the variable i to form an environment variable PATH1 or PATH2 etc.?

  • 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-08T11:54:34+00:00Added an answer on June 8, 2026 at 11:54 am
    i=1
    while [ $i -le ${NUM_OF_PATHS} ]
    do
      CPATH=$(eval echo \$\{PATH$i\})
      echo "PATH$i: $CPATH"
      let i++ 
    done
    

    eval combines and evaluates its parameters and executes the combined expression. Here, eval executes: echo ${PATH1}. In order to do this, we first escape the ${...} so that echo can receive them after eval. The only un-escaped special character is $ before i. eval expands this and strips off the escaped characters and executes echo with the result.

    So, CPATH=$(eval echo \$\{PATH$i\}) becomes CPATH=$(echo ${PATH1}) and CPATH gets the echo output.

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

Sidebar

Related Questions

I have the following gems defined in my environment.rb file: config.gem authlogic config.gem paperclip
I have two environment variables in apache config, I want to concatenate them into
I have a bunch of config.gem statements in my environment.rb file: config.gem fastercsv, :version
I have my checked my environment.rb config.time_zone = 'Prague' Nothing in development.rb regarding time
Is it possible for the apache2 user, http, to have environment variables like normal
I have no rails environment but I want to use cruisecontrol.rb as my Continous
In my Config.groovy I consolidate properties files in the following way: grails.config.locations << file:${userHome}/environment.properties
I have a Spring application-context.xml with PropertyPlaceholderConfigurer to get properties' values from .properties file.
I have an environment where 2 load-balanced clustered tomcats pointing to same application. When
At my company, we have tiered environment for our web applications (development, staging, production).

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.