LoginSignup
3
4

More than 5 years have passed since last update.

cdコマンドのシェルスクリプトを実行する方法

Posted at

目的

・cdコマンドによって、ディレクトリを移動するシェルスクリプトを作成する

通常のシェルスクリプト作成時の問題

・シェルスクリプトの実行終了とともに実行ディレクトリに戻ってしまう。

対処方法

通常の./とか、sh, bashではなく、sourceコマンドを利用して実行する
source **.sh

sourceコマンドは、自分自身で一つひとつのコマンドをタイプしたのと同じ状態になるらしい。
http://x68000.q-e-d.net/~68user/unix/pickup?source

同様に、この方法によりcdコマンドと同様にシェルスクリプト終了後に反映されない
"source"コマンドを実行するシェルスクリプトも実行可能になる。

3
4
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
3
4