Something like this should work:
search() { local i=1; for str in "${array[@]}"; do if [ "$str" = "$1" ]; then echo $i return else ((i++)) fi done echo "-1" }
Despite the fact that cyclic movement through the array to search for the index is certainly possible, this alternative solution with an associative array is more practical:
array=([1,os]="Linux" [1,type]="Test System" [2,os]="Windows" [2,type]="Work Station" [3,os]="Windows" [3,type]="Work Station") echo "number $1 is a ${array[$1,os]} ${array[$1,type]}"
source share