Section Next | Prev


004 where - CDPATH以下のディレクトリ検索

概要
環境変数 CDPATH の内容に従い、指定されたサブディレクトリの存在を確認する。

スクリプトと解説 - [text]
#スクリプト解説
1#! /bin/bash #
2# serch directory of cd #
3IFS=: 区切り文字を空白からコロン(:)に変更
4for n in $CDPATH CDPATH の内容を列挙型させる($IFSで分離)
5do #
6        if [ -d $n/$1 ]; then CDPATHのディレクトリ以下に引数で指定した サブディレクトリが存在すれば真
7                (cd $n/$1; pwd ) 上記で判定したディレクトリに移動し、ディレクトリを表示
8        fi #
9done #

実行例
$ echo $CDPATH
/home/ycos/:/etc/:/etc/sysconfig

$ where bin
/home/ycos/bin
$ where httpd
/etc/httpd
$ where network-scripts
/etc/sysconfig/network-scripts

Section Next | Prev