2
0

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.

WindowsのGit bashでシェルスクリプトを実行するショートカットを作る

Last updated at Posted at 2022-09-25

TL;DR

シェルスクリプトのショートカットを作り、右クリックメニューからプロパティを開きます。
「リンク先」項目に以下の内容を記述します。

ショートカットのプロパティのリンク先
C:\WINDOWS\system32\cmd.exe /c ""C:\Program Files\Git\bin\bash.exe" -i script.sh option"

解説

cmd /c

実行完了するとウインドウを閉じます。実行完了後にウインドウを閉じたくない場合はオプション/cの代わりに/kを使います。

"C:\Program Files\Git\bin\bash.exe"

gitのインストール時についてくるbash.exeのフルパスを指定します。
環境変数PATHbash.exeまでのパスが指定してあればbash.exeでも問題ありません。
今回はProgram Filesフォルダ以下に入っているので、スペースでコマンドが分割されないようにbash.exeまでのパスをダブルクォーテーションでくくっています。

bash.exe -i script.sh

bash.exeのオプション-iは「対話モードで実行」です。
-iがないとシェルスクリプト内の一部コマンドが実行されないようです。

"bash.exe -i script.sh option"

script.shは実行したいシェルスクリプトファイルを、optionはシェルスクリプトファイルに渡したいコマンド引数を指定できます。
optionはスペース区切りで列挙することで複数でも指定できます。
bash.exeがオプション付きシェルスクリプトを実行することをcmd.exeに伝えるため、シェルスクリプトを実行するコマンド全体をダブルクォーテーションでくくる必要があります。

2
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?