• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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