6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Zsh: no matches foundは(N)をつけると解消できる

Posted at

Zshで、「**/*.js」のようなglobパターンを使ってスクリプトを書いたとき、パターンにマッチするファイルが見つからないと「no matches found」というエラーが起きます。

たとえば、次のコードのように、拡張子がjsのファイル名を出力するものがあったとします。

main.zsh
echo **/*.js

これを実行したとき、jsファイルが1つ以上見つかれば、ファイル名が出力され正常終了します。

正常終了
a/x.js y.js

一方で、jsファイルがひとつもないと、次のようなエラーが出ます。

エラー終了
main.sh:1: no matches found: **/*.js

このエラーが発生すると、処理がそこで終了していまいます。

(N)をつけるとエラーを抑制できる

このエラーを抑制するには、(N)をパターンの末尾に追加します。

main.zsh
echo **/*.js(N)

これをつけて実行すると、マッチするファイルが見つからなくてもエラーになりません。

このNはnull globと呼ばれるものです。

6
1
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
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?