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

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 に答える
1

while ループを使用します。

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