First of all, please use ***
[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do
not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
I don't know much about csh and its variants, but I do know that it's not a good idea to use it for scripting, if at all. It just has too many parsing problems.
Top Ten Reasons not to use the C shell
(The site also has a more detailed primer on using the csh shell. Just go up a level.)
As for
bash scripting, a much better choice
, I suggest starting with the Bash Guide here:
http://mywiki.wooledge.org/BashGuide
Note that the bourne shell syntax and built-in features are quite different in many ways. There's no
foreach, for example, just
for.
In any case, loading an array from user input is quite easy:
Code:
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[@]}"
You just need to specify some condition for exiting the loop.
Edit: Come to think of it, it can be even easier if the entries are all single words, and you want to enter them on one line. You only need a single
read command with the
-a option.
Code:
echo 'Enter your array elements, separated by spaces:'
read -r -a array
You can even set it up to use a different separator, if you don't want to worry about whitespace:
Code:
echo 'Enter your array elements, colon-separated:'
IFS=: read -r -a array