LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-21-2004, 10:44 AM   #1
Frustin
Member
 
Registered: May 2002
Location: Essex, UK
Distribution: Debian, Redhat, AIX 5L
Posts: 512

Rep: Reputation: 30
script to check $PATH directories exist


Is there a script that i can use to check if the directories in $PATH exist?
 
Old 09-21-2004, 12:35 PM   #2
ky-lab_rat
Member
 
Registered: Jan 2004
Posts: 44

Rep: Reputation: 15
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
 
Old 09-21-2004, 12:37 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 09-21-2004, 01:20 PM   #4
wipe
Member
 
Registered: Jun 2004
Location: High Green
Distribution: Fedora Core 4
Posts: 180

Rep: Reputation: 30
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

Last edited by wipe; 09-21-2004 at 01:25 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if users exist in the system hindll01 Programming 12 09-28-2012 03:24 PM
Check if email exist or not proNick Linux - Software 2 08-27-2005 02:25 PM
How to check if a software exist in my computer Niceman2005 Linux - Newbie 4 12-28-2004 10:12 PM
How to check if array[0] doesn't exist? flamesrock Programming 3 11-05-2004 11:36 AM
when backingup directories, how to detect files already exist WarriorWarren Linux - General 10 04-06-2003 02:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration