The UNIX and Linux Forums  


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
Ubuntu shell script lucianvibz Shell Programming and Scripting 1 05-27-2008 10:47 AM
Need to write a script in UNIX to find a file if another file exists mmdawg Shell Programming and Scripting 1 05-04-2008 11:40 PM
Check File Exists and compare to previous day file script rbknisely Shell Programming and Scripting 3 02-07-2008 11:53 AM
unix script to check whether particular file exists and to find its size Balachandar Shell Programming and Scripting 9 02-05-2008 03:56 AM
If file exists (bourne shell) blakmk UNIX for Dummies Questions & Answers 2 11-19-2003 10:47 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 03-26-2008
m_kk m_kk is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 6
Chek if a file exists in Ubuntu and Cent OS using shell script

I have tried few examples in the internet but all of them are different and none worked. I need to check if a file exists in a directory if it does not then exit . here is what I have for now

$filename ="/usr/local/net/var/lib/directoryservice/sync.disable"
if [-e $filename ];
then
echo "The file exists"
else
echo "Does not exist"
fi

This gives me error saying the ="/usr/local/net/var/lib/directoryservice/sync.disable" is not a directory or file and -e option does not exist. I need to be working on ubuntu and centos.

Any help will be appreciated.

Thank you.
  #2 (permalink)  
Old 03-26-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 need a space between the opening square bracket and the -e. The opening square bracket -- believe it or not -- is the name of a command (also known as test) and like other commands, it needs to be its own space-separated token.

Also, you need to drop the dollar sign when assigning to a variable, and not have any spaces between the variable name, the equals sign, and the value.
  #3 (permalink)  
Old 03-26-2008
m_kk m_kk is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 6
Oh woow its unbelievable that such a small mistake would cost so much time. Thanks a lot it works fine now.
Closed Thread

Bookmarks

Tags
linux, ubuntu

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 10:48 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