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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:24:43+00:00 2026-06-17T12:24:43+00:00

First of all, let me state that I am very new to Bash scripting.

  • 0

First of all, let me state that I am very new to Bash scripting. I have tried to look for solutions for my problem, but couldn’t find any that worked for me.
Let’s assume I want to use bash to parse a file that looks like the following:

variable1 = value1
variable2 = value2

I split the file line by line using the following code:

cat /path/to/my.file | while read line; do
    echo $line      
done

From the $line variable I want to create an array that I want to split using = as a delimiter, so that I will be able to get the variable names and values from the array like so:

$array[0] #variable1
$array[1] #value1

What would be the best way to do this?

  • 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-17T12:24:43+00:00Added an answer on June 17, 2026 at 12:24 pm

    Set IFS to ‘=’ in order to split the string on the = sign in your lines, i.e.:

    cat file | while IFS='=' read key value; do
        ${array[0]}="$key"
        ${array[1]}="$value"
    done
    

    You may also be able to use the -a argument to specify an array to write into, i.e.:

    cat file | while IFS='=' read -a array; do
        ...
    done
    

    bash version depending.

    Old completely wrong answer for posterity:

    Add the argument -d = to your read statement. Then you can do:

    cat file | while read -d = key value; do
        $array[0]="$key"
        $array[1]="$value"
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, let me just state that I'm new to .NET so I
First of all let me tell you that i have read the following questions
First of all, let me say that I am not a professional coder -
I've got a weird problem with udp sockets. First of all, let me provide
First of all, apologize because I have seen some posts about this, but I
First of all, I am new to R (I started yesterday). I have two
First let me just state that coding without unit testing is just plain crazy.
So I have a problem that I want to use depth first search to
First of all I want to state that I've just started with Drupal so
Let me first state that I know next to nothing about LDAP and this

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.