unix - Storing values in an array using shell scripting -


this works fine since because i'm directly inputting data.

declare -a arr arr=( $(awk '/123456789/{print nr}' filename) ) echo ${arr[0]} echo ${arr[*]} 

bt when below, doesn't work. can u let me know how parameter 'name' can used in command below :

echo  enter search string:   read name declare -a arr arr=( $(awk '/"$name"/{print nr}' filename ) echo ${arr[0]} echo ${arr[*]} 

based on comments posting answer. script work you:

read -e -p "enter search string: " name #echo "name: [$name]" declare -a arr arr=( $(awk /"$name"'/{print nr}' x ) ) echo ${arr[0]} echo ${arr[*]} 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -