LoginSignup
2
2

More than 5 years have passed since last update.

スクリプト実行時のカレントディレクトリをスクリプトと同階層にする

Last updated at Posted at 2017-08-05

概要

スクリプトファイルをどこから実行しても、スクリプトファイルと同階層をカレントディレクトリとしたい時がある。
けっこう書くことが多いくせに、毎回調べてる感じがするので書いて覚える。

Windows(cmd)の場合

Sample.cmd
cd /d %~dp0
...

Linux(sh)の場合

Sample.sh
#!/bin/sh
cd `dirname $0`
...
2
2
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
2
2