#!/bin/bash IFS=" " read -r -a args <<< "$@" declare -A argv for((i=0;i<$#;i++)); do argv["${args[$i]}"]=$i done for i in "${!argv[@]}" do echo "index: $i" echo "value: ${argv[$i]}" done