Results 1 to 2 of 2
Hi all
I've a bash script to read user input and perform a task on it. But what id like is for the user to be able to enter a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 12-31-2012 #1Just Joined!
- Join Date
- Dec 2012
- Posts
- 6
Perform an action on a list/array of variables from user input in bash
Hi all
I've a bash script to read user input and perform a task on it. But what id like is for the user to be able to enter a list and perform the action on each of the list for as many as are entered.
#!/bin/bash
echo -n "Enter the list"
texta
textb
textc
read list
foreach
do
a_script text[a-c]
done
hope that makes sense...
can anyone help?
Thanks,
- 12-31-2012 #2Just Joined!
- Join Date
- Dec 2012
- Posts
- 6
Solved courtesy of David the H @ linuxquestions.org
for information...
echo 'Enter your array elements one at a time, followed by newlines.'
echo 'Type "exit" to finish.'
while read -r input ; do
[[ $input == exit ]] && break
array+=( "$input" )
done
echo 'You entered the following array elements:'
printf '%s\n' "${array[@]}"
cheers Dave.



