LoginSignup
60
59

More than 5 years have passed since last update.

Macでシェルスクリプトをダブルクリックで実行

Last updated at Posted at 2016-03-28

シェルスクリプトをダブルクリックで実行できると割りと便利なので、その方法をメモ

今回実行するスクリプト

hello.sh
echo 'hello world!'

普通に実行しようとするとエラーがでるので実行権限を与える

# そのまま実行しようとすると権限で弾かれる

$ ./hello.sh

#-> zsh: permission denied: ./hello.sh

# 実行権限を与える

$ chmod +x hello.sh
$ ./hello.sh

# -> hello world!

+i もしくは右クリックから情報を見るターミナルもしくはiTermで開くを選択

これでダブルクリックでシェルスクリプトが実行できるようになる

$ /Users/username/path/to/script/hello.sh ; exit;
hello world!

[Process completed]

追記
拡張子を.commandに変更する方法もあるらしい

# ファイル名を変更
$ mv hello.sh hello.command

# コピーする場合
$ cp hello.sh hello.command
60
59
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
60
59