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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Tcp_conn_req_max_q (CASE-sensitive?) Olli.Lang SUN Solaris 4 09-11-2008 03:03 AM
case sensitive "if [ -e $file ]"? jul Shell Programming and Scripting 2 05-08-2008 08:48 AM
Ignore case sensitive in Case Switch annelisa Shell Programming and Scripting 1 07-13-2006 04:36 AM
how to disable case sensitive on RHEL ? blesets UNIX for Dummies Questions & Answers 2 04-02-2006 09:47 PM
Is Hostname Case sensitive ????? ajphaj UNIX for Dummies Questions & Answers 3 02-16-2006 01:10 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 11-24-2008
msb65 msb65 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 89
Check if file is directory (-d) using case sensitive

Hi,

I am writing a bash script. At the beginning of the script there is a user defined variable which is a directory in which processed data will be moved. When running the script I would like to immediately make sure that the directory exists, and if not the script will error. The following code should do that:

OUTDIR='/Users/msb65/test_data'

if [ -d $OUT_DIR ]; then
echo '- OUT_DIR exists'
else
echo; echo; echo 'ERROR: OUT_DIR does not exist'
exit 1
fi

However, this test does NOT seem to be case sensitive. How can I make it so it is? Thanks.

Mike
  #2 (permalink)  
Old 11-24-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
First off [[ -d dirname ]] is case sensitive. Either there is another directory which matches or your script is doing something you do not want it to do in this case.

Is that code above identical to what is failing for you?
  #3 (permalink)  
Old 11-24-2008
msb65 msb65 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 89
Hi Jim,

Thanks for the reply. I notice that you are using double brackets while I am using single. How should that change the behavior?

Mike
  #4 (permalink)  
Old 11-24-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
You code works for me, and IS case sensitive:
Code:

# cat check
if [ -d $1 ]; then
echo '- OUT_DIR exists'
else
echo; echo; echo 'ERROR: OUT_DIR does not exist'
exit 1
fi

# ll
total 8
-rw-r--r-- 1 root root 107 Nov 24 12:56 check

# sh check Test


ERROR: OUT_DIR does not exist

# mkdir Test

# ll
total 16
-rw-r--r-- 1 root root  107 Nov 24 12:56 check
drwxr-xr-x 2 root root 4096 Nov 24 12:57 Test

# sh check Test

- OUT_DIR exists
# sh check test


ERROR: OUT_DIR does not exist
 #
  #5 (permalink)  
Old 11-24-2008
msb65 msb65 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 89
Hi Ikon,

That is interesting that similar code appears to be working differently on our two systems. I am using a Mac running Leopard. I wonder if there are nuances between our bash? On my system there is the directory: /Users/msb65/test_data/Olive

However, the test doesnt error when I substitute a lowercase "o" on "Olive":

$ dir='/Users/msb65/test_data/Olive'
$ if [ -d $dir ]; then echo hello; fi
hello

dir='/Users/msb65/test_data/olive'
$ if [ -d $dir ]; then echo hello; fi
hello

Why is this?

Mike
  #6 (permalink)  
Old 11-24-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Older file systems of OS X are not case sensitive. Google on leopard case sensitive file system.
Sponsored Links
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 04:39 AM.


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