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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:47:03+00:00 2026-06-02T04:47:03+00:00

This is the first time Im using a shell script ( #!/bin/sh ) and

  • 0

This is the first time Im using a shell script ( #!/bin/sh ) and Ive been working my way through it reading tutorials and the like but Im stuck on this reading and writing values of a key..

Im trying to read in key=value pairs from a config file of the form

key1_begin=abc
key1_end=def

key2_begin=123
key2_end=jkl

.. and so on

I would like the user to pass in parameters to the script like

something.sh 1 x y z

where the first parameter would serve as an that is used to modify the appropriate keys. So after I have checked that the directory exists and the file exists I source it using

source config.cfg

I then save the id using ID=$1 and access the keys using

echo key${ID}_begin 

so a read to obtain the value of the key would be

echo key${ID}_begin = $[key${ID}_begin]

where I expect to get ” key1_begin = abc ” but instead keep getting ” key1_begin = 0 “. The same command however seems to work work for numbers. For example using this command with an ID of 2 gives ” key2_begin = 123 “

Could someone please point me in the right direction as to why this works fine for numbers but not alphabets?

And what do I use to change the value of the variable? I am currently using “eval” but this again seems to only work with numbers

[ ! -z $2 ] && eval key${ID}_end=$3

Would really appreciate any advice / pointers with this.\

Thank you

  • 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-02T04:47:05+00:00Added an answer on June 2, 2026 at 4:47 am

    You most likely going to have to use an intermediary variable:

    key1_begin=abc
    var="key${ID}_begin"
    echo "$var=${!var}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time using stackoverflow. I've been unable to find out the
this is my first time using StAX for parsing XML documents (still in the
Sorry, this is my first time using this forum. Apparently people can edit my
I'm fairly new to both Django and Python. This is my first time using
This is the first time ever I'm using AJAX, and I want to do
This is my first time to create a report using iReport plugin in Netbeans
This is my first time doing mobile development with twitter. I'm using Adobe Flash
I'm using this XML classes for the first time and can't find this piece
I am using $SUB for the first time and have come across this problem.
I'm using this line to get the beginning time of the first day of

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.