LoginSignup
1
0

More than 3 years have passed since last update.

カスタムシェルコマンドの作り方

Posted at

カスタムコマンド用ディレクトリを作成

mkdir ~/custom_command

.zshrcを編集してPATHを通す

export PATH=$HOME/custom_command:$PATH

シェルの設定を反映

source ~/.zshrc

コマンドを作る

拡張子は必要ない。

touch test1

ファイルに実行権限を与える

chmod 700 test1

お好きなシェルスクリプトを書く

test1
#!/bin/sh

if [ $# = 0 ]; then
    echo "君、引数設定したの?"
    exit 1
elif [ $# != 1 ]; then
    echo "ごめん、引数1個で頼む!"
    exit 1
fi

if [ "$1" = 'hoge' ]; then
    echo "hogeなtest1だよ!"
elif [ "$1" = 'fuga' ]; then
    echo "fugaなtest1だよ!"
elif [ "$1" ]; then
    echo "そんな引数は許さないよ!"
    exit 1
fi

あとはどこからでもファイル名を叩くだけ!

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