Solved

DeteWildcard mask in shell script

Posted on 1998-12-21
7
238 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 58
Pressing cancel button with C# UI Automation 3 81
Window placement 17 87
NotAlone Challenge 20 84
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 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