54
46

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 5 years have passed since last update.

シェルスクリプト自身のパス取得

Last updated at Posted at 2013-03-01

シェルスクリプトでスクリプト自身のパスを取得する方法。
以下の処理でシェルの種類に依存せず(とは言っても bourne shell 系のみだが)
シェルスクリプト自身のパスを取得する事ができる筈。

example.sh
#!/bin/sh
# ${0} の dirname を取得
cwd=`dirname "${0}"`

# ${0} が 相対パスの場合は cd して pwd を取得
expr "${0}" : "/.*" > /dev/null || cwd=`(cd "${cwd}" && pwd)`

54
46
3

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
54
46

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?