Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to do multiple inputs into a variable

Status
Not open for further replies.

komark

Technical User
Sep 12, 2005
134
US
Hi,

I am trying to input the user input into a variable

ex:
echo "Please enter the filename:"
set file = $<

But how can i enter mulitple filenames so the user would input at the prompt:
file1
file2
file3

Thanks
Omar.
 
You appear to be using C shell... does it have to be written in C shell?

I'm not that familiar with C shell, but you could read them into an array using a loop...

Annihilannic.
 
#! /usr/bin/ksh

## a couple of ideas

list=

echo Please enter filenames separated by a space :

read list

echo "You entered : "

for aname in $list
do
echo "name : $aname"
done

## or ##

set -A fname

echo "Enter filenames, one on each line. Enter END to quit the input."
cnt=1
an=START

while [ $an == START ]
do
print $cnt
read aname;
# do other validations here
if [ $aname == END ]
then
echo exiting the loop.
an=$aname
else
fname[$cnt]=$aname
(( cnt=cnt+1 ))
fi
done

print you entered ${fname[*]}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top