Horje
bash length of array Code Example
get length of array bash
## define it
distro=("redhat" "debian" "gentoo")
 
## get length of $distro array
len=${#distro[@]}
 
## Use bash for loop 
for (( i=0; i<$len; i++ )); do echo "${distro[$i]}" ; done
bash length of array
# Basic syntax:
YOUR_VAR=( $YOUR_VAR ) # convert the string to an array
echo ${#YOUR_VAR[*]} # use the standard bash syntax to get the length of arrays

# Example usage:
YOUR_VAR='some string with words'
YOUR_VAR=( $YOUR_VAR )
echo ${#YOUR_VAR[*]}
--> 4

# Note, to convert the array back to a string, use:
YOUR_VAR="${YOUR_VAR[*]}"
bash size of array
echo "${#my_array[@]}"




Shell

Related
create new branch without losing changes Code Example create new branch without losing changes Code Example
bash show all file with same name Code Example bash show all file with same name Code Example
How do I select which GPU to run a job on? Code Example How do I select which GPU to run a job on? Code Example
bash write to file specific line Code Example bash write to file specific line Code Example
makepkg resolve auto dependencies Code Example makepkg resolve auto dependencies Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
17