If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > using if/else with utility

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-05, 16:50
ltsn ltsn is offline
Registered User
 
Join Date: Oct 2005
Posts: 3
using if/else with utility

I'm a newbie in programming shell scripts. I want to write a script for the following but I don't know how, anyone knows please help. thanks

if (success find a file "A" in the current directory)
echo "found it"

else (do something else)

I tried to use the find utility but got an error like if: Expression syntax
Reply With Quote
  #2 (permalink)  
Old 10-13-05, 17:14
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
Code:
if [ -f ./A ] ; then
  echo "found it"
else
  dosomethingelse
fi
The "[" is an alias for the programme called "test". For more details run "man test".
Reply With Quote
  #3 (permalink)  
Old 10-13-05, 19:37
ltsn ltsn is offline
Registered User
 
Join Date: Oct 2005
Posts: 3
Quote:
Originally Posted by n_i
Code:
if [ -f ./A ] ; then
  echo "found it"
else
  dosomethingelse
fi
The "[" is an alias for the programme called "test". For more details run "man test".
Thanks for quick reply, but when I run it I have something like this

Code:
Missing ]
Reply With Quote
  #4 (permalink)  
Old 10-13-05, 19:47
ltsn ltsn is offline
Registered User
 
Join Date: Oct 2005
Posts: 3
never mind, i think i got it, thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On