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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:48:21+00:00 2026-06-08T18:48:21+00:00

Thanks for your help in advance. I’m writing a simple bash script, which just

  • 0

Thanks for your help in advance. I’m writing a simple bash script, which just read each line of a file, and then store each line into a different variable. For example, I’d like the script to perform the following commands:

d1=AER
d2=BHR
d3=CEF
...

Therefore, I have a text file that has 10 lines, and each line is the content of the variables I’d like to store (e.g., AER), and I have the following test.sh script:

#!/bin/bash
for i in {1..10..1}
do
    $(d$i=$(sed -n ${i}p $HOME/textfile.txt))
done

However,when executing the script, it gave me

./test.sh: line 4: d1=AER: command not found
./test.sh: line 4: d2=BHR: command not found
./test.sh: line 4: d3=CEF: command not found
...

,instead of storing the characters into corresponding variables. Could somebody please identify where I did it wrong? Thank you so much!

  • 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-08T18:48:24+00:00Added an answer on June 8, 2026 at 6:48 pm

    The problem with your script is that if you need to interpolate a variable on the first line, bash thinks its the name of a program and tries to execute it. You can eval it, to make the variable:

    eval "d$i=$(sed ...)"
    

    but its much simpler to use the read bash built-in, since it takes line input to a specified variable. Here’s one way to do it:

    for ((i=1;; i++)); do
        read "d$i" || break;
    done < textfile.txt
    echo "$d1"
    echo "$d2"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi thanks in advance for your help. I'm just getting started learning Python and
Thanks in advance for your help. I have a need within an application to
Thanks in advance for your help experts. I want to be able to copy
First off, thanks in advance for your help. This issue is driving me nuts.
Hello and thanks for your help in advance. I am starting on the NHibernate
Thanks for your help! I'd like to output all companyName entries that have uploads
Thanks For your Valuable support, Now i m able to run shell script in
Ok. here's the operations i successfully code so far thank's to your help: Adittion:
Thank you for your interesting in my question. You can help me out from
thanks for your reading. I am trying to modify Jquery Nivo Zoom plugin to

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.