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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:26:42+00:00 2026-06-05T15:26:42+00:00

Because shells other than ksh do not support pass-by-reference, how can multiple arrays be

  • 0

Because shells other than ksh do not support pass-by-reference, how can multiple arrays be passed into a function in bash without using global variables, and in a way which allows any legal variable content to be included as an array element (no reserved sigils)?

  • 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-05T15:26:43+00:00Added an answer on June 5, 2026 at 3:26 pm

    Since bash 4.3

    As of 2016, modern bash supports pass-by-reference (a.k.a nameref attribute) as:

    demo_multiple_arrays() {
      local -n _array_one=$1
      local -n _array_two=$2
      printf '1: %q\n' "${_array_one[@]}"
      printf '2: %q\n' "${_array_two[@]}"
    }
    
    array_one=( "one argument" "another argument" )
    array_two=( "array two part one" "array two part two" )
    
    demo_multiple_arrays array_one array_two
    

    See also declare -n in the man page.


    Before bash 4.3

    This can be done safely by using a calling convention which puts number-of-arguments before each array, as such:

    demo_multiple_arrays() {
      declare -i num_args array_num;
      declare -a curr_args;
      while (( $# )) ; do
        curr_args=( )
        num_args=$1; shift
        while (( num_args-- > 0 )) ; do
          curr_args+=( "$1" ); shift
        done
        printf "$((++array_num)): %q\n" "${curr_args[@]}"
      done
    }
    

    This can then be called as follows:

    array_one=( "one argument" "another argument" )
    array_two=( "array two part one" "array two part two" )
    demo_multiple_arrays \
      "${#array_one[@]}" "${array_one[@]}" \
      "${#array_two[@]}" "${array_two[@]}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

because when I use the function getUser () do not get the correct id?
Because I've made .cpp files and then transferred them into .h files, the only
I'm sharing a git repository with a colleague, and because git does not propagate
First I'm not mad, because I use MVVM in WinForms-) I know about MVP
When using os.system() it's often necessary to escape filenames and other arguments passed as
I can't find this interface or other information about this: ok.addSelectionListener(new SelectionAdapter() { public
And it breaks the shell I'm trying to run because it doesn't know the
Because data from file look like this: line 1 is name (first last), next
Because my CSS3 animation uses over 50% of CPU in Chrome Browser 21.0 on
Because it takes me a lot of time to integrate the Sherlock Action Bar

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.