kb:tools:bash
Bash
Working with arrays:
#---- Create arrays ----# # Declare 'foo' as array # Accepts whitespace in string declare -a foo=("one" "two" "three 3") # ... or even as empty array foo=() foo+=("one") foo+=("two") #---- Iterate array ----# # Iterate by element # See 'https://stackoverflow.com/a/8880633' for why enclosing quotes for elem in "${foo[@]}"; do echo $elem done # Iterate by index len=${#array[@]} for (( i=0; i<$len; i++ )); do echo "$i : ${array[$i]}" done
kb/tools/bash.txt · Last modified: 19 months ago ( 2 May 2023) by 127.0.0.1