You would find the array keys with "${!foo[@]}"
(reference), so:
for i in "${!foo[@]}"; do
printf "%s\t%s\n" "$i" "${foo[$i]}"
done
Which means that indices will be in $i
while the elements themselves have to be accessed via ${foo[$i]}
More Related Contents:
- Correct Bash and shell script variable capitalization
- Using getopts to process long and short command line options
- How do I compare two string variables in an ‘if’ statement in Bash? [duplicate]
- Propagate all arguments in a bash shell script
- Brace expansion with a Bash variable – {0..$foo}
- “~/Desktop/test.txt: No such file or directory”
- Associative arrays: error “declare: -A: invalid option”
- How to put a line comment for a multi-line command [duplicate]
- How to calculate time elapsed in bash script?
- How to get Maven project version to the bash command line
- In bash, how do I bind a function key to a command?
- How do I get the directory where a Bash script is located from within the script itself?
- Bash: Syntax error: redirection unexpected
- Difference between return and exit in Bash functions
- LINES and COLUMNS environmental variables lost in a script
- How to kill all subprocesses of shell?
- Check if all of multiple strings or regexes exist in a file
- How to get the PID of a process that is piped to another process in Bash?
- How to reset COMP_WORDBREAKS without affecting other completion script?
- How to use a bash script variable with sed [duplicate]
- Fastest possible grep
- Assigning to a positional parameter [duplicate]
- Divide two variables in bash
- Printing asterisk (“*”) in bash shell
- Get exit code from subshell through the pipes
- Loop over tuples in bash?
- What does the curly-brace syntax ${var%.*} mean?
- Returning a boolean from a Bash function
- How to use Bash to create a folder if it doesn’t already exist?
- What is more portable? echo -e or using printf?