Bash: how can I use read to echo (or do things to) an array member -
array content
somecommand=$(cat /etc/somelog) #pseudo array creation
array=($somecommand) array length
arraylen=${#array[@]} for loop iterates array length
for (( i=0; i<${arraylen}; i++ )); adds someprefix (for readability )
$(($i + 1 )) appends number list (for clear options) starting @ 1
echo "$(($i + 1 )) ${arr[$i]/#/someprefix}" done printf "\n" echo "please enter 1-${arraylen} --> " asks user input
read anwser stores value (a case statement woud better # replace loop - concept script) trying work.
this need ### (i think?)
echo "${array[$anwser]}" # things #
you reading variable named $answer, indexing array $anwser.
Comments
Post a Comment