Solved

DeteWildcard mask in shell script

Posted on 1998-12-21
7
239 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
Technology Partners: 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!

 
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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