LoginSignup
1

More than 5 years have passed since last update.

ファイルの存在判定(+ readlink)

Posted at

こんにちは。
regular ファイルの存在を判定したい場合、test コマンドで、[ -f $file ] と判定するとリンクファイルの場合には非存在と判定されます。その場合にも対応するために readlink の助けを借りました(オリジナルファイルを追跡して判定)。

test_f.sh
#!/bin/sh
[ "$(uname)" = "Darwin" ] && READLINK="greadlink" || READLINK="readlink"
test -f $($READLINK -e $1)

なお上記のように GNU readlink を使うのではなく、どうしても BSD readlink で実現したい場合には、「Macで readlink -f を作る(シェルスクリプト)」などの方法があります。

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