LoginSignup
6
5

More than 5 years have passed since last update.

自作コマンド作成

Last updated at Posted at 2014-10-25

シェルで自作コマンド作成

パスが通っているディレクトリににスクリプトが書かれたファイルを置くと、そのファイル名でコマンドが実行できる。以下そのための手順。

echo $PATH
#出力結果に /home/ユーザー名/bin/ が含まれておりパスが通っていることを確認。
cd
mkdir bin
cd bin
vim newcommand

(newcommandの中身)


#!/bin/sh
echo 'newcommand実行'

chmod +x newcommand #実行権限を与える
which newcommand #newcommandがパス通っている場所(/home/ユーザー名/bin) にあることを確認
newcommand #実行

・$PATHの左に書かれているディレクトリのコマンドが優先して実行される
・パスを通すディレクトリを編集したいときは.bash_profileで設定

6
5
2

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
6
5