• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

DeteWildcard mask in shell script

I have a script I am working on in which I need to determine if there are any files with the last letters of ".log" in the file.

The current script if statement is

if (-e "*.log") then

#
# do my processing
#
endif

There are ".log" files in the directory. What is the correct format for the if statement.

Thanks,
Andrew

P.S. This should be a very easy question.
0
andrewmchorney
Asked:
andrewmchorney
1 Solution
 
aditya070797Commented:
Hi AndrewMcHorney,
              There are many ways of doing what you want. In ksh, here is what I would do:
Note that I use ksh which I believe is the most convinient shell to program in.

#
#!/bin/ksh

  if [[ $(\ls *.log 2>/dev/null | wc -l) -gt 0 ]]
  then
# Do your processing
   else
# Do not do your processing
  fi

An alternative would be:

#!/bin/ksh
  LOG_LIST=$(\ls *.log 2>/dev/null)
  if [[ ! -z $LOG_LIST ]]
  then
# Do your processing on the list:
#      for file in $LOG_LIST
#      do
#           process_file $file
#      done
#
  else
# Do something else
  fi

Thank you,
--Aditya.
0
 
andrewmchorneyAuthor Commented:
How about a version for csh which is what we use ?

I will attempt to translate to csh in the morning and try it.

0
 
ozoCommented:
if( { echo *.log  > & /dev/null } )then
#
# do my processing
#
endif
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
ahoffmannCommented:
or use csh instead ;-)
0
 
andrewmchorneyAuthor Commented:
The csh version worked quite well.
0
 
ahoffmannCommented:
Hmm, looking at your question, you're using csh sysntax.
So I assume you accepted  the answer 'cause you want to have
a sh syntax. Right?
0
 
andrewmchorneyAuthor Commented:
I used the solution from ozo.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now