LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   script to check $PATH directories exist (https://www.linuxquestions.org/questions/linux-software-2/script-to-check-%24path-directories-exist-233353/)

Frustin 09-21-2004 09:44 AM

script to check $PATH directories exist
 
Is there a script that i can use to check if the directories in $PATH exist?

ky-lab_rat 09-21-2004 11:35 AM

try this

Code:

#!/bin/sh
IFS=:
read dirs <<END
$PATH
END
for dir in $dirs
do
 if [ ! -e "$dir" ]
 then
  echo "$dir does not exist."
 else
  echo "$dir  exist."
 fi
done


druuna 09-21-2004 11:37 AM

This 'one liner' can do that for you:

for THIS_PATH in `echo $PATH | sed 's/:/ /g'`; do [[ ! -d $THIS_PATH ]] && echo "WARNING $THIS_PATH does not exist."; done

The scripted form would look like this:

Code:

#!/bin/bash
for THIS_PATH in `echo $PATH | sed 's/:/ /g'`
do
  [[ ! -d $THIS_PATH ]] && echo "WARNING $THIS_PATH does not exist."
done

Hope this helps.

wipe 09-21-2004 12:20 PM

This one-liner would suffice for me:

ls -d `echo $PATH|tr : ' '`

Notice how you can also check $? to see if they all exist (ls returns 0 if all went well, 1 if there's an error).

Regards
Simon


All times are GMT -5. The time now is 10:10 AM.