The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to check the existence of a file using korn shell? karthikprasathk AIX 3 06-19-2008 05:51 AM
how to check the existence of a file during ftp using korn shell? karthikprasathk AIX 1 06-19-2008 03:20 AM
Check existence of a login xavier054 UNIX for Advanced & Expert Users 10 03-06-2008 11:19 AM
Csh to check for existence of file Raynon Shell Programming and Scripting 9 12-05-2007 09:20 PM
How to check the file existence using shell scripting in Solaris-10 krevathi1912 SUN Solaris 2 11-26-2007 05:07 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-10-2008
Alalush Alalush is offline
Registered User
  
 

Join Date: Jul 2008
Location: Israel
Posts: 21
shell :: check directory existence

Hi All,

I have shell script and I need to check if some directory exist.
I'm don't have the information if that directory is written in upper case or lowcase or mixed.

Is there anyway to check the existence of that directory by ignoring
case senestive?

Thanks
  #2 (permalink)  
Old 09-10-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Well, let's say you were looking for Fred or FRED or fred in /home:

Code:
fred=$(ls -l /home | grep -xi 'd.*fred' | awk '{print $NF}')
if [[ "$fred ]]
then
    echo "$fred exists"
else
    echo "can't find any freds"
fi

Last edited by Annihilannic; 09-10-2008 at 03:29 AM.. Reason: no need for ^ and $ with grep -x
  #3 (permalink)  
Old 09-10-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
You forgot a closing quote in if [[ "$fred" ]]

If your find has an option -iname that's a good solution too.

Code:
find /path/to/dir -maxdepth 1 -type d -iname 'fred' -print

Last edited by era; 09-10-2008 at 03:30 AM.. Reason: find example
  #4 (permalink)  
Old 09-10-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Quote:
Originally Posted by era View Post
You forgot a closing quote in if [[ "$fred" ]]
Thanks.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0