如何接受多行输入到同一个脚本中。或者换句话说,使用以下脚本处理多个文件:
#!/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
使用 while 循环:
while read input_source
do
# Do something with $input_source
done
添加一个for循环:
#!/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
只需 cat 所有与输入模式匹配的文件-:
#!/bin/bash
echo 'Enter file names (wild cards OK)'
read input_source
cat $input_source | sort | uniq -c | head -10