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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:02:23+00:00 2026-06-05T04:02:23+00:00

I have a script where i have defined two arrays. Now depending on the

  • 0

I have a script where i have defined two arrays. Now depending on the array name passed (as parameter), i want to process the same in the function below. Earlier, i wasn’t even getting any element in variable ‘ARRAY’ until i used ${!}

Now the problem is that when i am printing the array content (or the number of elements in that array), i am getting only the first element.

Any suggestions?

Script:

#!/bin/bash

APP=$1

process_data() {
    ARRAY="${!1}"
    echo "No of array elements: ${#ARRAY[@]}"
    echo "Array content: ${ARRAY[@]}"
}


ORADATA=(
"oraserver/content:abcDaily/ORAServer/"
"oraserver/w3s-ix86:abcDaily/ORAServer/"
)

SQLDATA=(
"sqlserver/content:abcDaily/SQLServer/"
"sqlserver/w3s-ix86:abcDaily/SQLServer/"
)

process_data ${APP[@]}

Command:

-bash-2.05b$ ./testarray.sh ORADATA

Output:

No of array elements: 1
Array content: oraserver/content:abcDaily/ORAServer/
  • 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-05T04:02:25+00:00Added an answer on June 5, 2026 at 4:02 am

    Here’s a version without eval (so it handles shell metacharacters in the array values properly):

    #!/bin/bash
    
    APP=$1
    
    process_data() {
        ARRAYVAR="$1[@]"   # This just textually appends "[@]" to $1
        ARRAY=("${!ARRAYVAR}")   # Use indirect expansion to get contents of array, store as new array
        echo "No of array elements: ${#ARRAY[@]}"
        echo "Array content: ${ARRAY[@]}"
    }
    
    
    ORADATA=(
    "oraserver/content:abcDaily/ORAServer/"
    "oraserver/w3s-ix86:abcDaily/ORAServer/"
    )
    
    SQLDATA=(
    "sqlserver/content:abcDaily/SQLServer/"
    "sqlserver/w3s-ix86:abcDaily/SQLServer/"
    )
    
    process_data $APP   # Note that APP is not an array, so the [@] bit was irrelevant
    

    Example:

    $ ./testarray.sh ORADATA
    No of array elements: 2
    Array content: oraserver/content:abcDaily/ORAServer/ oraserver/w3s-ix86:abcDaily/ORAServer/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a protected function defined in a script block of a component defined
I have a function defined inside the script tags of head.(in a JSP) I
I have a script which creates a user-defined object like this: obj = new
I have an awk script that I have defined thus: #!/usr/bin/env awk BEGIN {
I have an Ant copy task (defined in a Maven script invoked by a
I have two applications deployed on tomcat. For each application I have defined their
working on an ANT build file, where I have two macros defined and need
I have a simple PHP script with a form that has two select fields,
I have a groovy DSL script like this: entity(attribute1:one, attribute2:two) so far so good.
I have a drop down list with two values (for now..) with other elements

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.