回答:
$ if test -d /the/dir; then echo "exist"; fi
test -d /the/dir
。test -d /the/dir && echo "exist" || echo "does not exist"
しかし、彼らは実際には同じです。
bash
!
tcsh
てい.tcshrc
ます。しかし、もっと重要なことは、これがOPの問題を説明したかもしれないということです。
シェルがBASHであると仮定します。
if [ -d /the/dir ]; then echo 'Exists'; else echo 'Not found'; fi
csh
またはtcsh
?
[ -d /home/bla/ ] && echo "exits"
[ -d /home/bla/ ] && echo "exist" ; [ ! -d /home/bla/ ] && echo "doesnt exist"
標準的な方法は、test(1)ユーティリティを使用することです。
test -d path
ここで、「パス」は問題のディレクトリのパス名です。
echo "Directory Exists"
。
シェルスクリプトにディレクトリが存在するかどうかを確認するには、次を使用できます。
dir=$1
if [ -d "$dir" ]; then
#means that $dir exists.
fi
反対をチェックするには、!
前に追加します-d ->[ ! -d ....]