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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:44:21+00:00 2026-06-03T07:44:21+00:00

Two things, first this is my first question in this forum and I do

  • 0

Two things, first this is my first question in this forum and I do apologise if the formating is all over the place. Second I have not written that many bash scripts, and it tend to be quite a long time between the scripts I produce.

That said, here is my question.

Is it possible to do something like this in bash (Clear array $array contains):
$array=()

Basically this is what I would like to do. I have a variable with array variable names in it:

array1=()  
array2=()  
arrayList="array1 array2"  


# In a function far far away
for array in $arrayList
do  
    eval arr=("\"\${$array[@]\"")  

    for index in ${!arr[@]}
    do
        echo "${arr[$index]}"
    done
    # Here is the big "?", I like to clear the array that $array refers to.
    $array=()  
done

My arrays contain strings that include “” (space) and this is why I use the eval statement. Not sure it’s needed but at least it’s working. The script is more or less working as I want it too, but I need to clear the arrays in the $arrayList, and I rather not hardcode it somewhere, even though that would be easy.

  • 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-03T07:44:23+00:00Added an answer on June 3, 2026 at 7:44 am

    Probably the simplest thing to do is just unset them. An unset variable will act identically to an empty array in most contexts, and unset $array ought to work fine.

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

Sidebar

Related Questions

I am asking two things. The first question is am I doing this correctly?
I have two things I need this for, these should explain what I mean:
First of all I'd welcome edits to the title of this question, I couldn't
Actually this is a two parts question: First, is ip2long a good IP validator?
Hi I want to know how to do two things with LINQ This question
I have a solution with two relevant (to this question) projects, and a few
Two things: Firstly - I have version 2 of a website located in a
(Followup to this question ) After surviving the first wave of incoming shipments (9
I have tried to find the answer to this question on both the Spring
I have two questions regarding to html table layout. First I will provide some

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.