Ubuntu では ~/.bashrc を直接編集する代わりに ~/.bash_aliases を作ることを推奨されている.
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
|
この if 文の意味を「~/.bash_aliases が存在するならば」という意味だと思っていたのだが,
正しくは
「~/.bash_aliases がファイルのパスならば」
という意味だった.ちなみにディレクトリのパスならばという意味の時は -d.
ファイル・ディレクトリ問わず存在するならばという意味の時は -e.
を使うようだ.
[Bash] ファイルやディレクトリの存在をチェックする方法
まとめると次のようになる.
ファイル or ディレクトリが存在するならば
if [ -e TARGET ]; then
echo "TARGET exists."
fi
|
ファイルが存在するならば
if [ -f FILE ]; then
echo "FILE is path of file."
fi
|
ディレクトリが存在するならば
if [ -d DIR ]; then
echo "DIR is path of directory."
fi
|
0 件のコメント:
コメントを投稿