Requirement: Check for the existence of the directories mentioned in PATH env variable.
The bash script:
#!/bin/sh
IFS=:
read dirs <<END
$PATH
END
for dir in $dirs
do
[ ! -e "$dir" ] && echo "$dir not exist" \
|| echo "$dir exist"
done
Executing the above bash script:
$ ./check-PATH.sh
/usr/local/bin exist
/usr/bin exist
/bin exist
/usr/X11R6/bin exist
/cygdrive/c/WINDOWS/system32 exist
/cygdrive/c/WINDOWS exist
/usr/bin exist
/usr/lib/sanity not exist
Read more about Bash IFS (Internal Field Separator) from tldp.org

0 comments:
Post a Comment