Sponsored Content
Top Forums Shell Programming and Scripting File exist for multiple files Post 302902835 by vbe on Thursday 22nd of May 2014 11:55:37 AM
Old 05-22-2014
I this case your -f may work:
Code:
if [ -f $Direct/$file* ]
then
   echo "File present"
else
   echo "File  not present"
fi

But it must be clear in your mind that the test tested ONE file that matched...
It will understand the variable $file* as one filename

So trust Corona688, if this happens to work, it only because it tested one file! And so will not solve your problem if you want to test for multiple files, it is more a question of what you are trying to achive Here the presence of one file suffice to fullfill the condition, therefore you will never know if you had more than one, I would answer like Corona688:
For multiple files file test operators are not to be used( unless of course you use a loop...)

Last edited by vbe; 05-22-2014 at 01:11 PM..
This User Gave Thanks to vbe For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare data in 2 files and delete if file exist

Hi there, I have written a script called "compare" (see below) to make comparison between 2 files namely test_put.log and Output_A0.log #!/bin/ksh while read file do found="no" while read line do echo $line | grep $file > /dev/null if then echo $file found found="yes" break fi... (3 Replies)
Discussion started by: lweegp
3 Replies

2. Shell Programming and Scripting

How to check a file exist and do a copy of other files

Hi, I would like to perform bash which would check the file A.txt to be size 0 or not. If the size is 0, I would copy file B.txt to replace A.txt. Please help. Thanks. -Jason (6 Replies)
Discussion started by: ahjiefreak
6 Replies

3. Shell Programming and Scripting

Delete files if they exist

In a directory a number of files named res0.om res1.om ... resN.om where N can be any unknown number between 1 and 999 Please help me filling out the gaps in the following csh script: I need to delete all files exept res0.om The easy way is rm res1* rm res2* rm res3* rm res4*... (5 Replies)
Discussion started by: pederlol
5 Replies

4. UNIX for Dummies Questions & Answers

copy files as space exist in file name..

Hi, i am having a directory in which files are having space in the name . $ls -1 aa b.txt my file.pdf lost file.csv foo_file.txti want to copy those file to some where with date +%F as extension . But it failed for the file having space. #!/bin/sh ls -1 >tt for var in `cat tt` do b=$var... (2 Replies)
Discussion started by: posix
2 Replies

5. Shell Programming and Scripting

Find out whether files exist.

I have the following data stored in a file. 1 /home/file13 /home/file2 2 /home/file41 /home/file654 3 /home/file61 /home/file45 4 /home/file81 /home/file43 ... I want to print the first column provided the files represented by the second and third column exist. How to do that? (3 Replies)
Discussion started by: kevintse
3 Replies

6. Shell Programming and Scripting

check if multiple folders exist

I want to check if some directories with common prefix exist under current directory with bash, say, I have dictories like: dirct_1 dirct_2 dirct_3 ... in the current directory. I did: if then echo " directories exist " else echo " directories not exist " fi (3 Replies)
Discussion started by: cristalp
3 Replies

7. Shell Programming and Scripting

Code to remove files when corresponding file doesnt exist isnt working.

I am trying to add some code to the begging of a script so that it will remove all the .transcript files, when their is no coressponding .wav file. But it doesnt work. This is the code I have added: for transcriptfile in `$voicemaildir/*.transcript`; do wavfile=`echo $transcriptfile | cut -d'.'... (2 Replies)
Discussion started by: ghurty
2 Replies

8. UNIX for Dummies Questions & Answers

Checking if multiple directories exist

I need to create multiple directories if those directories do not exist already. How would you go by doing this. What I have so far. array=(one two three) for I in ${array} do if ] then mkdir ${I} fi doneI have a good feeling this is done incorrectly. The error I am... (2 Replies)
Discussion started by: jrymer
2 Replies

9. Shell Programming and Scripting

Shell script to check files if exist else touch the file

Hi All, Thanks in Advance I wrote the following code if then echo "version is 1.1" for i in "subscriber promplan mapping dedicatedaccount faflistSub faflistAcc accumulator pam_account" do FILE="SDP_DUMP_$i.csv" echo "$FILE" ... (5 Replies)
Discussion started by: aealexanderraj
5 Replies

10. UNIX for Beginners Questions & Answers

Check if 10 files exist

Hi All, Whenever i get 10 files(file names like sales*) then another file need to create. May i know how to implement this in KSH. (4 Replies)
Discussion started by: siddireddy
4 Replies
CONTROL.CTL(5)							File Formats Manual						    CONTROL.CTL(5)

NAME
control.ctl - specify handling of Usenet control messages DESCRIPTION
The file <pathetc in inn.conf>/control.ctl is used to determine what action is taken when a control message is received. If <usecon- trolchan in inn.conf> is ``true'', it is read by the controlchan script, which can be invoked as channel program by innd(8). When con- trol.ctl is modified, controlchan notices this automatically and reload it. If <usecontrolchan in inn.conf> is ``false'', it is read by the parsecontrol script, which is called by all the control scripts. (For an explanation of how the control scripts are invoked, see innd(8).) The file consists of a series of lines; blank lines and lines beginning with a number sign (``#'') are ignored. All other lines consist of four fields separated by a colon: message:from:newsgroups:action The first field is the name of the message for which this line is valid. It should be either the name of the control message or the word ``all'' to mean that it is valid for all messages. The second field is a shell-style pattern that matches the email address of the person posting the message. (The poster's address is first converted to lowercase.) The matching is done using the shell's case statement (or the equivalent); see sh(1) for details. If the control message is ``newgroup'' or ``rmgroup'' then the third field specifies the shell-style pattern that must match the group being created or removed. If the control message is ``checkgroups'' then the third field specifies the shell-style pattern that is used to determine which newsgroups are processed for checking. If the control message is of a different type, then this field is ignored. The fourth field specifies what action to take on control messages that match this line. The following actions are understood: doit The action requested by the control message should be performed. In some cases, the control script will also send mail to <USER specified with --with-news-master at configure>, but if notification of the action should always be sent, doit=mail should be used instead (see below). doifarg If the control message has an argument, this is treated as a ``doit'' action. If no argument was given, it is treated as a ``mail'' entry. This is used in ``sendsys'' entries script so that a site can request its own newsfeeds(5) entry by posting a ``sendsys mysite'' article. On the other hand, sendsys ``bombs'' ask that the entire newsfeeds file be sent to a forged reply-to address; by using ``doifarg'' such messages will not be processed automatically. (Processing ``sendsys'' control messages is still not recom- mended, even with this work-around, unless they are authenticated in some fashion. The risk of having news servers turned into anonymous mail bombing services is too high.) doit=file The action is performed, but a log entry is written to the specified log file, file. If file is the word ``mail'' then the record is mailed. A null string is equivalent to /dev/null (in other words, with a null string, nothing is logged). A pathname that starts with a slash is taken as the absolute filename to use as the log. Otherwise, the log entry is written to <pathlog in inn.conf>/file.log. The log is written by writelog (see newslog(8)). drop No action is taken; the message is ignored. verify-* If the value starts with the string ``verify-'' (for example, ``verify-news.announce.newgroups'') then PGP verification of the con- trol message will be done using the key issued by the ``user'' defined by the rest of the string -- ``news.announce.newsgroups'' in this example. If no logging is specified (with =file mentioned below), notification of successful ``newgroup'' and ``rmgroup'' mes- sages and the output of ``checkgroups'' messages will be mailed to the news administrator. verify-*=file PGP verification is done as for the ``verify-*'' entries, and a log entry is written to the specified file. (In the case of ``checkgroups'' messages, this means the shell script output of the ``checkgroups'' message will be written to that file.) log A one-line log notice is sent to standard error. innd(8) normally directs this to the file <pathlog in inn.conf>/errlog. log=file A log entry is written to the specified log file, file, which is interpreted as described above. mail A mail message is sent to the news administrator. Processing of a ``checkgroups'' message will never actually change the active(5) file. The difference between an action of doit (or ver- ify) and an action of mail for ``checkgroups'' control messages lies only in what mail is sent; doit will mail the news administrator a shell script to create, delete, or modify newsgroups to match the ``checkgroups'' message, whereas mail will just mail the entire message. In either case, the news administrator will have to take action to implement the ``checkgroups'' and if the mail is ignored, nothing will be changed. Lines are matched in order; the last match found in the file is the one that is used. For example, with the following three lines: newgroup:*:*:drop newgroup:group-admin@isc.org:comp.*|humanities.*|misc.*|news.*| rec.*|sci.*|soc.*|talk.*:verify-news.announce.newgroups newgroup:kre@munnari.oz.au:aus.*:mail A newgroup coming from ``group-admin'' at a ISC machine will be honored if it is one of the listed hierarchies and if it has a valid signa- ture with the ``news.announce.newgroups'' key. If ``kre'' posts a newgroup message creating ``aus.foo'', then mail will be sent. All other newgroup messages are ignored. Use of the verify action for processing ``newgroup'', ``rmgroup'', and ``checkgroups'' messages is strongly recommended. Abuse of control messages is rampant, and authentication via PGP signatures is currently the only reliable way to be sure that a control message comes from who it claims to be from. Most major hierarchies are now using PGP-authenticated control messages. In order to use verify actions, the PGP key ring of the news user must be populated with the PGP keys of the hierarchy maintainers whose control messages you want to honor. For more details on PGP-authenticated control messages and the URL for downloading the PGP keys of major hierarchies, see pgpverify(8). Control messages of type ``cancel'' are handled internally by innd(8) and cannot be controlled by any of the mechanisms described here. HISTORY
Written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews. This is revision 1.11.2.1, dated 2000/08/17. SEE ALSO
controlchan(8), inn.conf(5), innd(8), newsfeeds(5), pgpverify(8), scanlogs(8). CONTROL.CTL(5)
All times are GMT -4. The time now is 04:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy