同じスクリプトに複数行の入力を受け入れるにはどうすればよいですか。つまり、次のスクリプトを使用して複数のファイルを処理するには、次のようにします。
#!/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
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
while ループを使用します。
while read input_source
do
# Do something with $input_source
done