Syntax | Description |
---|---|
arr=() |
Create an empty array |
arr=(1 2 3) |
Initialize array |
${arr[2]} |
Retrieve third element |
${arr[@]} |
Retrieve all elements |
${!arr[@]} |
Retrieve array indices |
${#arr[@]} |
Calculate array size |
arr[0]=3 |
Overwrite 1st element |
arr+=(4) |
Append value(s) |
str=$(ls) |
Save ls output as a string |
arr=( $(ls) ) |
Save ls output as an array of files |
${arr[@]:s:n} |
Retrieve n elements starting at index s |
Created
March 12, 2021 11:16
-
-
Save hakandilek/e2fdfbbe0c383a6ca2e8dc96ba40a97e to your computer and use it in GitHub Desktop.
bash arrays
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment