1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

bash/複数ファイルを対象に処理する

Last updated at Posted at 2019-03-24

コマンドラインの引数を、全部処理する

while [ "$1" != "" ]
do
  echo "$1"
  shift
done

lsの結果(ファイル)を一つずつ何かする

DIR="."
IFS=$'\n'
for FILE in `ls "$DIR"`
do
  echo $FILE
done

ファイルを1行づつREADしてなんかするbash

引用元

BUFIFS=$IFS
IFS=

exec 3< 入力ファイル名
while read FL 0<&3
do
  処理
done
exec 3<&-

IFS=$BUFIFS

ファイルを読み込んでなんかする

TMPF=`mktemp tmp.XXXXXX`
ls > $TMPF

while read INFILE
do
  echo INFILE:$INFILE
done < "$TMPF"

ヒアドキュメントにファイル一覧を書いて、これを全部処理する

while read infile
do
  echo INFILE:$infile:
done << __EOT__
file1
file2
__EOT__
1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?