0

如何接受多行输入到同一个脚本中。或者换句话说,使用以下脚本处理多个文件:

#!/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
4

3 回答 3

1

使用 while 循环:

while read input_source 
do
# Do something with $input_source
done
于 2013-04-19T21:42:43.097 回答
1

添加一个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
于 2013-04-19T21:44:43.697 回答
1

只需 cat 所有与输入模式匹配的文件-:

#!/bin/bash
echo 'Enter file names (wild cards OK)'
read input_source
cat $input_source | sort | uniq -c | head -10
于 2013-04-19T21:46:36.270 回答