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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -