![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|