Bash Array – How to Declare an Array of Strings in a Bash Script

Bash scripts give you a convenient way to automate command line tasks.

With Bash, you can do many of the same things you would do in other scripting or programming languages. You can create and use variables, execute loops, use conditional logic, and store data in arrays.

While the functionality may be very familiar, the syntax of Bash can be tricky. In this article, you will learn how to declare arrays and then how to use them in your code.

How to Declare an Array in Bash

Declaring an array in Bash is easy, but pay attention to the syntax. If you are used to programming in other languages, the code might look familiar, but there are subtle differences that are easy to miss.

To declare your array, follow these steps:

  • Give your array a name
  • Follow that variable name with an equal sign. The equal sign should not have any spaces around it
  • Enclose the array in parentheses (not brackets like in JavaScript)
  • Type your strings using quotes, but with no commas between them

Your array declaration will look something like this:

That's it! It's that simple.

How to Access an Array in Bash

There are a couple different ways to loop through your array. You can either loop through the elements themselves, or loop through the indices.

How to Loop Through Array Elements

To loop through the array elements, your code will need to look something like this:

To break that down: this is somewhat like using forEach in JavaScript. For each string (str) in the array (myArray), print that string.

The output of this loop looks like this:

Note : The @ symbol in the square brackets indicates that you are looping through all of the elements in the array. If you were to leave that out and just write for str in ${myArray} , only the first string in the array would be printed.

How to Loop Through Array Indices

Alternatively, you can loop through the indices of the array. This is like a for loop in JavaScript, and is useful for when you want to be able to access the index of each element.

To use this method, your code will need to look something like the following:

The output will look like this:

Note : The exclamation mark at the beginning of the myArray variable indicates that you are accessing the indices of the array and not the elements themselves. This can be confusing if you are used to the exclamation mark indicating negation, so pay careful attention to that.

Another note : Bash does not typically require curly braces for variables, but it does for arrays. So you will notice that when you reference an array, you do so with the syntax ${myArray} , but when you reference a string or number, you simply use a dollar sign: $i .

Bash scripts are useful for creating automated command line behavior, and arrays are a great tool that you can use to store multiple pieces of data.

Declaring and using them is not hard, but it is different from other languages, so pay close attention to avoid making mistakes.

Veronica is a librarian by trade with a longtime computer programming habit that she is currently working on turning into a career. She enjoys reading, cats, and programming in React.

If you read this far, thank the author to show them you care. Say Thanks

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

A Complete Guide on How To Use Bash Arrays

The Bash array variables come in two flavors, the one-dimensional indexed arrays , and the associative arrays . The indexed arrays are sometimes called lists and the associative arrays are sometimes called dictionaries or hash tables . The support for Bash Arrays simplifies heavily how you can write your shell scripts to support more complex logic or to safely preserve field separation.

This guide covers the standard bash array operations and how to declare ( set ), append , iterate over ( loop ), check ( test ), access ( get ), and delete ( unset ) a value in an indexed bash array and an associative bash array . The detailed examples include how to sort and shuffle arrays.

👉 Many fixes and improvements have been made with Bash version 5, read more details with the post What’s New in GNU Bash 5?

Difference between Bash Indexed Arrays and Associative Arrays

How to declare a bash array.

Arrays in Bash are one-dimensional array variables. The declare shell builtin is used to declare array variables and give them attributes using the -a and -A options. Note that there is no upper limit (maximum) on the size (length) of a Bash array and the values in an Indexed Array and an Associative Array can be any strings or numbers, with the null string being a valid value.

👉 Remember that the null string is a zero-length string, which is an empty string. This is not to be confused with the bash null command which has a completely different meaning and purpose.

Bash Indexed Array (ordered lists)

You can create an Indexed Array on the fly in Bash using compound assignment or by using the builtin command declare . The += operator allows you to append a value to an indexed Bash array.

With the declare built-in command and the lowercase “ -a ” option, you would simply do the following:

Bash Associative Array (dictionaries, hash table, or key/value pair)

You cannot create an associative array on the fly in Bash. You can only use the declare built-in command with the uppercase “ -A ” option. The += operator allows you to append one or multiple key/value to an associative Bash array.

⚠️ Do not confuse -a (lowercase) with -A (uppercase). It would silently fail. Indeed, declaring an Indexed array will accept subscript but will ignore it and treat the rest of your declaration as an Indexed Array, not an Associative Array.
👉 Make sure to properly follow the array syntax and enclose the subscript in square brackets [] to avoid the " Bash Error: must use subscript when assigning associative array " .

When to use double quotes with Bash Arrays?

A great benefit of using Bash Arrays is to preserve field separation. Though, to keep that behavior, you must use double quotes as necessary. In absence of quoting, Bash will split the input into a list of words based on the $IFS value which by default contain spaces and tabs.

Array Operations

How to iterate over a bash array (loop).

As discussed above, you can access all the values of a Bash array using the * (asterisk) notation. Though, to iterate through all the array values you should use the @ (at) notation instead.

How to get the Key/Value pair of a Bash Array? (Obtain Keys or Indices)

When looping over a Bash array it’s often useful to access the keys of the array separately of the values. This can be done by using the ! (bang) notation.

How to get a Bash Array size? (Array length)

Another useful aspect of manipulating Bash Arrays is to be able to get the total count of all the elements in an array. You can get the length (i.e. size) of an Array variable with the # (hashtag) notation.

How to remove a key from a Bash Array or delete the full array? (delete)

The unset bash builtin command is used to unset (delete or remove) any values and attributes from a shell variable or function. This means that you can simply use it to delete a Bash array in full or only remove part of it by specifying the key. unset take the variable name as an argument, so don’t forget to remove the $ (dollar) sign in front of the variable name of your array. See the complete example below.

Detailed Examples & FAQ

How to shuffle the elements of an array in a shell script.

There are two reasonable options to shuffle the elements of a bash array in a shell script. First, you can either use the external command-line tool shuf that comes with the GNU coreutils, or sort -R in older coreutils versions. Second, you can use a native bash implementation with only shell builtin and a randomization function. Both methods presented below assume the use of an indexed array, it will not work with associative arrays.

The shuf command line generates random permutations from a file or the standard input. By using the -e option, shuf would treat each argument as a separate input line. Do not forget to use the double-quote otherwise elements with whitespaces will be split . Once the array is shuffled we can reassign its new value to the same variable.

How to sort the elements of an Array in a shell script?

How to get a subset of an array.

The shell parameter expansions works on arrays which means that you can use the substring Expansion ${string:<start>:<count>} notation to get a subset of an array in bash. Example: ${myArray[@]:2:3} .

The notation can be use with optional <start> and <count> parameters. The ${myArray[@]} notation is equivalent to ${myArray[@]:0} .

How to check if a Bash Array is empty?

How to check if a bash array contains a value.

In order to look for an exact match, your regex pattern needs to add extra space before and after the value like (^|[[:space:]])"VALUE"($|[[:space:]]) .

With the Bash Associative Arrays, you can extend the solution to test values with [[ -z "${myArray[$value]}" ]] .

How to store each line of a file into an indexed array?

The easiest and safest way to read a file into a bash array is to use the mapfile builtin which read lines from the standard input. When no array variable name is provided to the mapfile command, the input will be stored into the $MAPFILE variable. Note that the mapfile command will split by default on newlines character but will preserve it in the array values, you can remove the trailing delimiter using the -t option and change the delimiter using the -d option.

  • Getting started with Bash
  • Awesome Book
  • Awesome Community
  • Awesome Course
  • Awesome Tutorial
  • Awesome YouTube
  • Accessing Array Elements
  • Array Assignments
  • Array from string
  • Array insert function
  • Array Iteration
  • Array Length
  • Array Modification
  • Associative Arrays
  • Destroy, Delete, or Unset an Array
  • List of initialized indexes
  • Looping through an array
  • Reading an entire file into an array
  • Associative arrays
  • Avoiding date using printf
  • Bash Arithmetic
  • Bash history substitutions
  • Bash on Windows 10
  • Bash Parameter Expansion
  • Brace Expansion
  • Case statement
  • CGI Scripts
  • Chain of commands and operations
  • Change shell
  • Color script output (cross-platform)
  • Conditional Expressions
  • Control Structures
  • co-processes
  • Copying (cp)
  • Creating directories
  • Customizing PS1
  • Cut Command
  • Decoding URL
  • Design Patterns
  • File execution sequence
  • File Transfer using scp
  • getopts : smart positional-parameter parsing
  • global and local variables
  • Handling the system prompt
  • Here documents and here strings
  • Internal variables
  • Job Control
  • Jobs and Processes
  • Jobs at specific times
  • Keyboard shortcuts
  • Listing Files
  • Managing PATH environment variable
  • Navigating directories
  • Networking With Bash
  • Pattern matching and regular expressions
  • Process substitution
  • Programmable completion
  • Read a file (data stream, variable) line-by-line (and/or field-by-field)?
  • Redirection
  • Script shebang
  • Scripting with Parameters
  • Select keyword
  • Sleep utility
  • Splitting Files
  • The cut command
  • true, false and : commands
  • Type of Shells
  • Typing variables
  • Using "trap" to react to signals and system events
  • When to use eval
  • Word splitting

Bash Arrays Array Assignments

List Assignment

If you are familiar with Perl, C, or Java, you might think that Bash would use commas to separate array elements, however this is not the case; instead, Bash uses spaces:

Create an array with new elements:

Subscript Assignment

Create an array with explicit element indices:

Assignment by index

Assignment by name (associative array)

Dynamic Assignment

Create an array from the output of other command, for example use seq to get a range from 1 to 10:

Assignment from script's input arguments:

Assignment within loops:

where $REPLY is always the current input

Got any Bash Question?


  • Advertise with us
  • Privacy Policy

Get monthly updates about new articles, cheatsheets, and tricks.

Next: The Directory Stack , Previous: Aliases , Up: Bash Features   [ Contents ][ Index ]

Bash provides one-dimensional indexed and associative array variables. Any variable may be used as an indexed array; the declare builtin will explicitly declare an array. There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Indexed arrays are referenced using integers (including arithmetic expressions (see Shell Arithmetic )) and are zero-based; associative arrays use arbitrary strings. Unless otherwise noted, indexed array indices must be non-negative integers.

An indexed array is created automatically if any variable is assigned to using the syntax

The subscript is treated as an arithmetic expression that must evaluate to a number. To explicitly declare an array, use

is also accepted; the subscript is ignored.

Associative arrays are created using

Attributes may be specified for an array variable using the declare and readonly builtins. Each attribute applies to all members of an array.

Arrays are assigned to using compound assignments of the form

where each value may be of the form [ subscript ]= string . Indexed array assignments do not require anything but string . When assigning to indexed arrays, if the optional subscript is supplied, that index is assigned to; otherwise the index of the element assigned is the last index assigned to by the statement plus one. Indexing starts at zero.

Each value in the list undergoes all the shell expansions described above (see Shell Expansions ).

When assigning to an associative array, the words in a compound assignment may be either assignment statements, for which the subscript is required, or a list of words that is interpreted as a sequence of alternating keys and values: name =( key1 value1 key2 value2 … ). These are treated identically to name =( [ key1 ]= value1 [ key2 ]= value2 … ). The first word in the list determines how the remaining words are interpreted; all assignments in a list must be of the same type. When using key/value pairs, the keys may not be missing or empty; a final missing value is treated like the empty string.

This syntax is also accepted by the declare builtin. Individual array elements may be assigned to using the name [ subscript ]= value syntax introduced above.

When assigning to an indexed array, if name is subscripted by a negative number, that number is interpreted as relative to one greater than the maximum index of name , so negative indices count back from the end of the array, and an index of -1 references the last element.

The ‘ += ’ operator will append to an array variable when assigning using the compound assignment syntax; see Shell Parameters above.

Any element of an array may be referenced using ${ name [ subscript ]} . The braces are required to avoid conflicts with the shell’s filename expansion operators. If the subscript is ‘ @ ’ or ‘ * ’, the word expands to all members of the array name . These subscripts differ only when the word appears within double quotes. If the word is double-quoted, ${ name [*]} expands to a single word with the value of each array member separated by the first character of the IFS variable, and ${ name [@]} expands each element of name to a separate word. When there are no array members, ${ name [@]} expands to nothing. If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. This is analogous to the expansion of the special parameters ‘ @ ’ and ‘ * ’. ${# name [ subscript ]} expands to the length of ${ name [ subscript ]} . If subscript is ‘ @ ’ or ‘ * ’, the expansion is the number of elements in the array. If the subscript used to reference an element of an indexed array evaluates to a number less than zero, it is interpreted as relative to one greater than the maximum index of the array, so negative indices count back from the end of the array, and an index of -1 refers to the last element.

Referencing an array variable without a subscript is equivalent to referencing with a subscript of 0. Any reference to a variable using a valid subscript is legal, and bash will create an array if necessary.

An array variable is considered set if a subscript has been assigned a value. The null string is a valid value.

It is possible to obtain the keys (indices) of an array as well as the values. ${! name [@]} and ${! name [*]} expand to the indices assigned in array variable name . The treatment when in double quotes is similar to the expansion of the special parameters ‘ @ ’ and ‘ * ’ within double quotes.

The unset builtin is used to destroy arrays. unset name [ subscript ] destroys the array element at index subscript . Negative subscripts to indexed arrays are interpreted as described above. Unsetting the last element of an array variable does not unset the variable. unset name , where name is an array, removes the entire array. unset name [ subscript ] behaves differently depending on the array type when given a subscript of ‘ * ’ or ‘ @ ’. When name is an associative array, it removes the element with key ‘ * ’ or ‘ @ ’. If name is an indexed array, unset removes all of the elements, but does not remove the array itself.

When using a variable name with a subscript as an argument to a command, such as with unset , without using the word expansion syntax described above, the argument is subject to the shell’s filename expansion. If filename expansion is not desired, the argument should be quoted.

The declare , local , and readonly builtins each accept a -a option to specify an indexed array and a -A option to specify an associative array. If both options are supplied, -A takes precedence. The read builtin accepts a -a option to assign a list of words read from the standard input to an array, and can read values from the standard input into individual array elements. The set and declare builtins display array values in a way that allows them to be reused as input.

You don't know Bash: An introduction to Bash arrays

hands programming

WOCinTech Chat. Modified by CC BY-SA 4.0

Although software engineers regularly use the command line for many aspects of development, arrays are likely one of the more obscure features of the command line (although not as obscure as the regex operator =~ ). But obscurity and questionable syntax aside, Bash arrays can be very powerful.

Programming and development

  • Red Hat Developers Blog
  • Programming cheat sheets
  • Try for free: Red Hat Learning Subscription
  • eBook: An introduction to programming with Bash
  • Bash Shell Scripting Cheat Sheet
  • eBook: Modernizing Enterprise Java

Wait, but why?

Writing about Bash is challenging because it's remarkably easy for an article to devolve into a manual that focuses on syntax oddities. Rest assured, however, the intent of this article is to avoid having you RTFM.

A real (actually useful) example

To that end, let's consider a real-world scenario and how Bash can help: You are leading a new effort at your company to evaluate and optimize the runtime of your internal data pipeline. As a first step, you want to do a parameter sweep to evaluate how well the pipeline makes use of threads. For the sake of simplicity, we'll treat the pipeline as a compiled C++ black box where the only parameter we can tweak is the number of threads reserved for data processing: ./pipeline --threads 4 .

The first thing we'll do is define an array containing the values of the --threads parameter that we want to test:

In this example, all the elements are numbers, but it need not be the case—arrays in Bash can contain both numbers and strings, e.g.,  myArray=(1 2 "three" 4 "five") is a valid expression. And just as with any other Bash variable, make sure to leave no spaces around the equal sign. Otherwise, Bash will treat the variable name as a program to execute, and the = as its first parameter!

Now that we've initialized the array, let's retrieve a few of its elements. You'll notice that simply doing echo $allThreads will output only the first element.

To understand why that is, let's take a step back and revisit how we usually output variables in Bash. Consider the following scenario:

Say the variable $type is given to us as a singular noun and we want to add an s at the end of our sentence. We can't simply add an s to $type since that would turn it into a different variable,  $types . And although we could utilize code contortions such as echo "Found 42 "$type"s" , the best way to solve this problem is to use curly braces: echo "Found 42 ${type}s" , which allows us to tell Bash where the name of a variable starts and ends (interestingly, this is the same syntax used in JavaScript/ES6 to inject variables and expressions in template literals ).

So as it turns out, although Bash variables don't generally require curly brackets, they are required for arrays. In turn, this allows us to specify the index to access, e.g.,  echo ${allThreads[1]} returns the second element of the array. Not including brackets, e.g., echo $allThreads[1] , leads Bash to treat [1] as a string and output it as such.

Yes, Bash arrays have odd syntax, but at least they are zero-indexed, unlike some other languages (I'm looking at you, R ).

Looping through arrays

Although in the examples above we used integer indices in our arrays, let's consider two occasions when that won't be the case: First, if we wanted the $i -th element of the array, where $i is a variable containing the index of interest, we can retrieve that element using: echo ${allThreads[$i]} . Second, to output all the elements of an array, we replace the numeric index with the @ symbol (you can think of @ as standing for all ): echo ${allThreads[@]} .

Looping through array elements

With that in mind, let's loop through $allThreads and launch the pipeline for each value of --threads :

Looping through array indices

Next, let's consider a slightly different approach. Rather than looping over array elements , we can loop over array indices :

Let's break that down: As we saw above, ${allThreads[@]} represents all the elements in our array. Adding an exclamation mark to make it ${!allThreads[@]} will return the list of all array indices (in our case 0 to 7). In other words, the for loop is looping through all indices $i and reading the $i -th element from $allThreads to set the value of the --threads parameter.

This is much harsher on the eyes, so you may be wondering why I bother introducing it in the first place. That's because there are times where you need to know both the index and the value within a loop, e.g., if you want to ignore the first element of an array, using indices saves you from creating an additional variable that you then increment inside the loop.

Populating arrays

So far, we've been able to launch the pipeline for each --threads of interest. Now, let's assume the output to our pipeline is the runtime in seconds. We would like to capture that output at each iteration and save it in another array so we can do various manipulations with it at the end.

Some useful syntax

But before diving into the code, we need to introduce some more syntax. First, we need to be able to retrieve the output of a Bash command. To do so, use the following syntax: output=$( ./ ) , which will store the output of our commands into the variable $output .

The second bit of syntax we need is how to append the value we just retrieved to an array. The syntax to do that will look familiar:

The parameter sweep

Putting everything together, here is our script for launching our parameter sweep:

What else you got?

In this article, we covered the scenario of using arrays for parameter sweeps. But I promise there are more reasons to use Bash arrays—here are two more examples.

Log alerting

In this scenario, your app is divided into modules, each with its own log file. We can write a cron job script to email the right person when there are signs of trouble in certain modules:

API queries

Say you want to generate some analytics about which users comment the most on your Medium posts. Since we don't have direct database access, SQL is out of the question, but we can use APIs!

To avoid getting into a long discussion about API authentication and tokens, we'll instead use JSONPlaceholder , a public-facing API testing service, as our endpoint. Once we query each post and retrieve the emails of everyone who commented, we can append those emails to our results array:

Note here that I'm using the jq tool to parse JSON from the command line. The syntax of jq is beyond the scope of this article, but I highly recommend you look into it.

As you might imagine, there are countless other scenarios in which using Bash arrays can help, and I hope the examples outlined in this article have given you some food for thought. If you have other examples to share from your own work, please leave a comment below.

But wait, there's more!

Since we covered quite a bit of array syntax in this article, here's a summary of what we covered, along with some more advanced tricks we did not cover:

One last thought

As we've discovered, Bash arrays sure have strange syntax, but I hope this article convinced you that they are extremely powerful. Once you get the hang of the syntax, you'll find yourself using Bash arrays quite often.

Bash or Python?

Which begs the question: When should you use Bash arrays instead of other scripting languages such as Python?

To me, it all boils down to dependencies—if you can solve the problem at hand using only calls to command-line tools, you might as well use Bash. But for times when your script is part of a larger Python project, you might as well use Python.

For example, we could have turned to Python to implement the parameter sweep, but we would have ended up just writing a wrapper around Bash:

Since there's no getting around the command line in this example, using Bash directly is preferable.

Time for a shameless plug

This article is based on a talk I gave at OSCON , where I presented the live-coding workshop You Don't Know Bash . No slides, no clickers—just me and the audience typing away at the command line, exploring the wondrous world of Bash.

This article originally appeared on Medium and is republished with permission.

User profile image.


Related content.

A community building a barn

Bash Arrays Explained: A Simple Guide With Examples

Get to grips with Bash arrays—how to declare them, manipulate them, and delete them.

Arrays are data stores used to hold values that have some relation to one another. Unlike in most programming languages, Bash arrays can store values of different data types in the same array.

Bash has two types of arrays: indexed arrays and associative arrays. For indexed arrays, the indexes begin from 0 to (n-1), as is common in most languages. However, arrays in Bash are sparse. This means that you can assign the (n-1)th array element without having assigned the (n-2)th element.

In this tutorial, you will learn how to work with arrays in Bash. Let's get started.

Defining Arrays

There are three ways you can define arrays in Bash. Similar to Bash variables, arrays need to be initialized at creation. The only exception to this is if you're using the declare keyword. You also need to be sure that no space is left on either side of the assignment operator as you're initializing the array.

The first method is compound assignment of values to the array name. There are two ways to do this:

In the first compound assignment, the values in the round brackets are assigned sequentially from the index [0] to [3] .

However, in the second, the values are assigned to an index in whichever order the programmer has indicated.

Related: What Are Environment Variables in Linux? Everything You Need to Know

If you took close notice to arr2 , you'll notice that index [2] was left out. The array will still be created without any errors thrown. This assignment is actually a demonstration of sparse storage in Bash arrays as we touched on earlier.

Notice that there are no commas separating the array values. The values are simply separated by spaces.

The second method indirectly declares the array. You can just start assigning values to null array elements:

The third way is to explicitly declare the array with the keyword declare :

Operations on Arrays

To access array elements, use this syntax: ${array[index]}

If you need to print out the entire array instead, use the @ symbol as the

index of ${array[index]} :

To find out the number of elements in the array, use the # symbol as shown below:

You may also need to modify array elements—see the example below on how to do so. It's similar to how you add a new element. The only difference is that you're replacing a value to an index that already has a value.

Associative Arrays

An array that has arbitrary values as its keys is called an associative array. These arrays are used to store related key-value pairs.

Related: How to Turn Bash Scripts Into Clickable Apps Using AppleScript

To define an associative array, you need to do so explicitly using the keyword declare .

You can access a member element in the same way you do indexed arrays:

If you wish to print out all the values, you can use the @ symbol as shown below:

If you want to print out all the array keys, you can use the @ and ! symbols as demonstrated below:

To find the number of elements the associative array has, use the same syntax you'd use with indexed arrays (demonstrated in the last section).

If you wish to delete an array item or the entire array, use the syntax below:

Using the printf Command

You may have noticed that this whole article uses the echo command to output data to the shell. The echo command works for this tutorial but has few features and flexibility when it comes to string formatting.

However, the printf command offers more specific formatting options that make Bash scripting a breeze. Learning the printf function will surely enhance your string formatting experience and efficiency in Bash.


  1. What Is the Abbreviation for “assignment”?

    According to Purdue University’s website, the abbreviation for the word “assignment” is ASSG. This is listed as a standard abbreviation within the field of information technology.

  2. What Is a Deed of Assignment?

    In real property transactions, a deed of assignment is a legal document that transfers the interest of the owner of that interest to the person to whom it is assigned, the assignee. When ownership is transferred, the deed of assignment show...

  3. What Is a Notice of Assignment?

    A Notice of Assignment is the transfer of one’s property or rights to another individual or business. Depending on the type of assignment involved, the notice does not necessarily have to be in writing, but a contract outlining the terms of...

  4. Copying a Bash array fails

    Assigning arrays to variables in Bash script seems rather complicated: ... name[*]} expand to the indices assigned in array variable name. The

  5. Bash Array

    How to Declare an Array in Bash · Give your array a name · Follow that variable name with an equal sign. The equal sign should not have any spaces

  6. How to use bash array in a shell script

    ... arrays in bash. Create indexed arrays on the fly. We can create indexed arrays with a more concise syntax, by simply assign them some values:

  7. A Complete Guide on How To Use Bash Arrays

    Bash Indexed Array (ordered lists). You can create an Indexed Array on the fly in Bash using compound assignment or by using the builtin command

  8. Bash Tutorial => Array Assignments

    Example# · List Assignment. If you are familiar with Perl, C, or Java, you might think that Bash would use commas to separate array elements, however this is

  9. 10.2. Array variables

    #!/bin/bash # This is # # First, we test whether bash supports arrays.

  10. Assigning value to array at certain index [duplicate]

    I would advise in the future not saying "a code", it does not sounds well. A shell script usually is best saved in a file with an ".sh"

  11. Arrays (Bash Reference Manual)

    Indexed array assignments do not require anything but string . When assigning to indexed arrays, if the optional subscript is supplied, that index is assigned

  12. You don't know Bash: An introduction to Bash arrays

    Otherwise, Bash will treat the variable name as a program to execute, and the = as its first parameter! Now that we've initialized the array, let's retrieve a

  13. Bash Arrays Explained: A Simple Guide With Examples

    This means that you can assign the (n-1)th array element without having assigned the (n-2)th element. In this tutorial, you will learn how to

  14. Arrays in Shell Scripts

    The default array that's created is an indexed array. If you specify the index names, it becomes an associative array and the elements can be