LoginSignup
1
0

More than 3 years have passed since last update.

【ShellScript】zshでカスタムコマンドを追加する

Last updated at Posted at 2021-01-26

環境

  • mac OS Catalina version 10.15.7
  • zsh 5.7.1 (x86_64-apple-darwin19.0)

目的

  • どこからでも呼び出せるカスタムコマンドを作成
% aaa
Hello, World!

実装

  • ~/commands拡張子のない シェルスクリプトを作成する
% mkdir ~/commands
% touch ~/commands/aaa
  • aaa を開き以下の通り編集
#!/bin/zsh

echo "Hello, World!"
  • ~/commands にパスを通す
% open ~/.zshrc
zshrc
# 以下を追加
export PATH=$PATH:~/commands
  • パスの変更を適応
% source ~/.zshrc
  • コマンドに対して権限を付与
% chmod 777 ~/commands/aaa
  • 確認
% aaa
Hello, World!

権限の付与について

  • chmod でファイルに対して権限を付与
  • 今回は今後の拡張を考えて読み込み・書き込み・実行権限を与えている
  • 詳しくは chmod コマンド
1
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
1
0