
Ubuntuのユーザのホームディレクトリにbinディレクトリを作成します。binディレクトリに、実行形式のファイルを配置するとパスを指定しなくても実行することができます。
記事の目次
ホームディレクトリにbinディレクトリを作成する!
ホームディレクトリに、binディレクトリを作成します。
$ mkdir ~/bin
シェルを配置する!
binディレクトリにシェルを配置します。
ls -l ~/bin total 4 -rwxr-xr-x 1 usradmin usradmin 44 Dec 7 22:32 wol_enable.sh
bashのファイルの補完が可能であることを確認する!
wolのみを入力して、Tabキーを押し、「wol_enable.sh」が表示されることを確認します。
$ wol_enable.sh
PATH追加の設定を確認する!
PATH環境へのbinディレクトリの追加は、「.bash_profile」であらかじめ行われています。
$ cat .profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
おわりに
ホームディレクトリにbinディレクトリを追加すると、PATH環境変数の設定を追加することなくシェルを起動することができます。
関連記事
