Solved

DeteWildcard mask in shell script

Posted on 1998-12-21
7
223 Views
Last Modified: 2013-12-26
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
Comment
Question by:andrewmchorney
7 Comments
 

Accepted Solution

by:
aditya070797 earned 20 total points
ID: 1294953
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
 

Author Comment

by:andrewmchorney
ID: 1294954
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
 
LVL 84

Expert Comment

by:ozo
ID: 1294955
if( { echo *.log  > & /dev/null } )then
#
# do my processing
#
endif
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 1294956
or use csh instead ;-)
0
 

Author Comment

by:andrewmchorney
ID: 1294957
The csh version worked quite well.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1294958
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
 

Author Comment

by:andrewmchorney
ID: 1294959
I used the solution from ozo.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now