User Tools

Site Tools


program_lang:bash

This is an old revision of the document!


BASH

array

Define an array

allThreads=(1 2 4 8 16 32 64 128)

List all Items from array

${allThreads[@]}

List the first item

${logPaths[0]}

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
program_lang/bash.1609532716.txt.gz · Last modified: 2021/01/01 21:25 by 127.0.0.1