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