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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:14:02+00:00 2026-06-18T09:14:02+00:00

I want to create a variable with its name partly dynamic and export it

  • 0

I want to create a variable with its name partly dynamic and export it from my bash shell script. I have been trying to do it the following way. No success though. Please tell me where I am wrong.

#!/bin/bash
CURRENT_PROCESS_ID=$$
var=METASTORE_JDBC_DRIVER_$CURRENT_PROCESS_ID
echo $var
export $var='1'

execution command

bash <filename>.sh

I am hoping the script would create an environmental variable like METASTORE_JDBC_DRIVER_8769 and I should be able to use that out of the script but when I do
echo $METASTORE_JDBC_DRIVER_8769 outside the script, doesn’t give me anything. Any suggestions/ideas are welcomed.

  • 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-18T09:14:04+00:00Added an answer on June 18, 2026 at 9:14 am

    Export exports variables into the current shell context. By running your script with bash it gets set in that shell’s context. You need to source the file to have it run in the current shell context.

    source <filename>.sh
    

    Just to show the difference between a sub-shell and source:

    [nedwidek@yule ~]# bash test.sh
    METASTORE_JDBC_DRIVER_8422
    [nedwidek@yule ~]# env |grep META
    [nedwidek@yule ~]# source test.sh
    METASTORE_JDBC_DRIVER_8143
    [nedwidek@yule ~]# env |grep META
    METASTORE_JDBC_DRIVER_8143=1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a schema with with a name passed by variable. Example:
I have a js variable with many functions, and I want to create in
I want to create a shell script so that I can type gc program_name.c
I have returned a result_array() in $categories variable and now I want to create
Possible Duplicate: Create new class from a Variable in Java I have a string
I want to create a quick function that will console.log a variable name and
I have a data frame with several variables. What I want is create a
i want create multiple search where statement $where_search is a multiple condition from post
i want create a custom json data from the mssql 2008 results so that
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =

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.