Reputation: 317
How can I accept multiple-line input into a same script. Or in other words to process multiple files with the following script:
#!/bin/bash
echo 'Enter file names (wild cards OK)'
read input_source
if test -f "$input_source"
then
sort $var | uniq -c | head -10
fi
Upvotes: 0
Views: 293
Reputation: 17288
Just cat all the files that match the input pattern-:
#!/bin/bash
echo 'Enter file names (wild cards OK)'
read input_source
cat $input_source | sort | uniq -c | head -10
Upvotes: 1
Reputation: 242343
Add a for loop:
#!/bin/bash
echo 'Enter file names (wild cards OK)'
read files
for input_source in $files ; do
if test -f "$input_source" ; then
sort $var | uniq -c | head -10 # You probably should include $input_source somewhere
fi
done
Upvotes: 1
Reputation: 129539
Use a while loop:
while read input_source
do
# Do something with $input_source
done
Upvotes: 1