User input to specify array name [bash] -


i started learning bash/shell fun, , i'm trying create simple script should take user input, should name of pre-built array, , say each item in array pause in between.

here's have far:

#!/bin/sh array=("foo" "bar" "baz")  read -p "which array should read you? " answer  item in ${answer[@]}     "$item [[slnc 1000]]" done 

please let me know if can point me in right direction!

you can access array using variable array name this:

#!/bin/bash  array=("foo" "bar" "baz") read -p "which array should read you? " answer  tmp="$answer"[@];  item in "${!tmp}";     echo "$item [[slnc 1000]]" done 

then use above script as:

bash arr.sh array should read you? array foo [[slnc 1000]] bar [[slnc 1000]] baz [[slnc 1000]] 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -