You can use it like this:
## declare an array variable declare -a arr=("element1" "element2" "element3") ## now loop through the above array for i in "${arr[@]}" do echo "$i" # or do whatever with individual element of the array done # You can access them using echo "${arr[0]}", "${arr[1]}" also
Also works for multi-line array declaration
declare -a arr=("element1" "element2" "element3" "element4" )
Related Posts:
- What is a list in Bash?
- Multi-dimensional arrays in Bash
- How to sort an array in Bash
- How do I pause my shell script for a second before continuing?
- How do I split a string on a delimiter in Bash?
- How to split a string into an array in Bash?
- In the shell, what does ” 2>&1 ” mean?
- Extract substring in Bash
- Ubuntu says “bash: ./program Permission denied” [closed]
- In the shell, what does ” 2>&1 ” mean?
- How do I use a regex in a shell script?
- How to concatenate string variables in Bash
- -bash: syntax error near unexpected token `)’
- How to grep for case insensitive string in a file?
- An example of how to use getopts in bash
- Difference between wait and sleep
- Multi-line string with extra space (preserved indentation)
- Multi-line string with extra space (preserved indentation)
- ‘\r’: command not found – .bashrc / .bash_profile [duplicate]
- ‘\r’: command not found – .bashrc / .bash_profile [duplicate]
- How can I check if a directory exists in a Bash shell script?
- How do I iterate over a range of numbers defined by variables in Bash?
- How to split a string into an array in Bash?
- How do I iterate over a range of numbers defined by variables in Bash?
- “unary operator expected” error in Bash if condition
- What does “-ne” mean in bash?
- “sed” command in bash
- How can I declare and use Boolean variables in a shell script?
- How to reload .bashrc settings without logging out and back in again?
- How can I declare and use Boolean variables in a shell script?
- How to reload .bash_profile from the command line?
- What is the purpose of “&&” in a shell command?
- How to generate random number in Bash?
- Replace one substring for another string in shell script
- How to check if a variable is set in Bash?
- “[ ]” vs. “[[ ]]” in Bash shell
- How do I split a string on a delimiter in Bash?
- Pseudo-terminal will not be allocated because stdin is not a terminal
- How can I compare numbers in Bash?
- Open and write data to text file using Bash?
- How can I count all the lines of code in a directory recursively?
- How can I kill a process by name instead of PID, on Linux?
- Given two directory trees, how can I find out which files differ by content?
- Which characters need to be escaped when using Bash?
- How to remove the quotes when reading a variable in jq in shell?
- Shell: How to call one shell script from another shell script?
- Pseudo-terminal will not be allocated because stdin is not a terminal
- find: missing argument to -exec
- How do I set a variable to the output of a command in Bash?
- ./configure : /bin/sh^M : bad interpreter
- Is there a TRY CATCH command in Bash
- How to check if an environment variable exists and get its value?
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
- How to convert a string to lower case in Bash?
- Is there a “goto” statement in bash?
- Run a string as a command within a Bash script
- Create a new file in git bash
- Badly placed ()’s error with the following shell script
- How to specify the private SSH-key to use when executing shell command on Git?
- Sorting data based on second column of a file
- Writing a simple shell in C using fork/execvp
- Speed up rsync with Simultaneous/Concurrent File Transfers?
- Variable interpolation in the shell
- chmod: changing permissions of ‘my_script.sh’: Operation not permitted
- What’s the meaning of the parameter -e for bash shell command line?
- zip error – Nothing to do
- What does set -e mean in a bash script?
- What does set -e mean in a bash script?
- Check existence of input argument in a Bash shell script
- Associative arrays in Shell scripts
- How to split one string into multiple strings separated by at least one space in bash shell?
- Copy multiple files from one directory to another from Linux shell
- Shell script not running, command not found
- source command not found in sh shell
- Printing from a declared array in MIPS
- Print array elements on separate lines in Bash?
- Difference between sh and Bash
- How to parse XML in Bash?
- Integer expression expected error in shell script
- How do I know the script file name in a Bash script?
- What is the difference between double and single square brackets in bash?
- What is “-bash: !”: event not found”
- How to add a timestamp to bash script log?
- Colors in bash after piping through less?
- How to run command as user who has /usr/sbin/nologin as Shell?
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- How to declare an array in Python?
- For-each over an array in JavaScript
- How to append something to an array?
- How to use execvp()
- How to use execvp() to execute a command
- TypeError: list indices must be integers or slices, not str
- How do I deal with a filename that starts with the hyphen (-) character?
- Sorting an array of objects by property values
- How can I remove a specific item from an array?
- What is a reverse shell?
- How do I check if an array includes a value in JavaScript?
- Meaning of “! -S” in shell script
- How to dynamically allocate arrays in C++
- How to dynamically allocate arrays in C++