LoginSignup
20
21

More than 5 years have passed since last update.

.phpで始まるすべてのファイルを一括でシンタックスチェックする

Posted at

コマンド

.phpのPHPスクリプトをまとめてシンタックスチェックするには以下のようにする。

$ find ./ -name "*.php" | xargs -n1 php -l

説明

find ./ -name "*.php"
./ のカレントディレクトリで、末尾が .phpのファイルをリストアップする

| xargs -n1 php -l
パイプ |xargs -n1をつなぐ。

xargs [オプション] [コマンド [初期引数]]

コマンドを渡すとそれを実行してくれる便利なxargsに、
php -lというシンタックスチェックのコマンドを渡す。

-n オプションは、引数をいくつ渡すか、つまり、php -lというコマンドに
いくつの引数を渡すかということ。

指定しないと
$ php -l index.php index2.php
と実行しているのと同じことになるが、これだとphp -l の特性上、はじめの index.phpしかチェックしてくれない。

-n1 として引数の最大値を1にすると、
1つ目のindex.phpをチェックする。
1つ以上、引数があった場合は、引数の分だけ複数回実行する。

結果的にfindで見つかった複数ファイルの分だけ、シンタックスチェックを繰り返し実行してくれるという事になる。

 参考

http://itpro.nikkeibp.co.jp/article/COLUMN/20140331/547143/
https://hydrocul.github.io/wiki/commands/xargs.html

20
21
0

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
20
21