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

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -