[comp.unix.questions] Problems with rm -f

jstewart@rodan.acs.syr.edu (Ace Stewart) (05/15/91)

System: Sun 4/490 running 4.1_PSR_A

Problem: When running a "rm -f" on files that may or may not be in a
sub-directory, the -f doesn't seem to suppress the error output if a
file doesn't exist. Script as follows:

----------------
% ls .Mail/drafts			Listing of directory
1	2
3	,1
,4

% rm -f .Mail/drafts/,*			Remove the , files (temp files)
%					All okay!  :)

% rm -f .Mail/drafts/,*			Do it again, _problems!_
No match.
%
----------------

What the heck is the -f option there for if it still throws up at you
if files in a sub-directory don't exist? It works fine if you are _in_
a that directory (i.e. 'rm -f ,*'  run twice in the sub-directory
suppresses errors correctly)

Comments/suggestions/help? Am I doing something incredibly stupid?

--Ace


-- 
    Ace Stewart | Affiliation: Eastman Kodak Company, Rochester, New York
jstewart@rodan.acs.syr.edu jstewart@sunrise.bitnet jstewart@mothra.cns.syr.edu
   jstewart@sunspot.cns.syr.edu     ace@suvm.bitnet     rsjns@suvm.bitnet

pfalstad@phoenix.princeton.edu (Paul Falstad) (05/15/91)

>% rm -f .Mail/drafts/,*         Remove the , files (temp files)
>%             All okay!  :)
>
>% rm -f .Mail/drafts/,*         Do it again, _problems!_
>No match.
>%
>----------------
>
>What the heck is the -f option there for if it still throws up at you
>if files in a sub-directory don't exist? It works fine if you are _in_
>a that directory (i.e. 'rm -f ,*'  run twice in the sub-directory
>suppresses errors correctly)

csh handles the * expansion, not rm; it's csh that's complaining that
there are no matches for ",*".  So in the second case, rm is never even
executed.  The -f flag is useless in either case, because the shell
would never pass the names of nonexistent files along to rm (because you are
using globbing).  I have no idea why this worked if you were in the
directory.

Do something like "rm .Mail/drafts/,* >& /dev/null", or use a different
shell.

--
Paul Falstad                     | 10 PRINT "PRINCETON CS"
pfalstad@phoenix.princeton.edu   | 20 GOTO 10

rickert@mp.cs.niu.edu (Neil Rickert) (05/15/91)

In article <1991May14.190816.17169@rodan.acs.syr.edu> jstewart@rodan.acs.syr.edu (Ace Stewart) writes:
>Problem: When running a "rm -f" on files that may or may not be in a
>sub-directory, the -f doesn't seem to suppress the error output if a
>file doesn't exist. Script as follows:
>
>% rm -f .Mail/drafts/,*			Do it again, _problems!_
>No match.
>%

  That message is not coming from 'rm'.  It is coming from your shell,
probably /bin/csh.  When you use '*' in a command, you are asking the shell
to expand '*' into a list of matching file names.  Here it is just telling
you that there were not matching names.  If the message bothers you, try
'set nonomatch' to see if this turns it off.  Or use a different shell.

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  Neil W. Rickert, Computer Science               <rickert@cs.niu.edu>
  Northern Illinois Univ.
  DeKalb, IL 60115                                   +1-815-753-6940

djm@eng.umd.edu (David J. MacKenzie) (05/15/91)

In article <1991May14.190816.17169@rodan.acs.syr.edu> jstewart@rodan.acs.syr.edu (Ace Stewart) writes:

> Problem: When running a "rm -f" on files that may or may not be in a
> sub-directory, the -f doesn't seem to suppress the error output if a
> file doesn't exist. Script as follows:

> % rm -f .Mail/drafts/,*			Do it again, _problems!_
> No match.

That's the C Shell printing that message -- rm never even gets run, if
you give a globbing pattern that doesn't match any files.
--
David J. MacKenzie <djm@eng.umd.edu> <djm@ai.mit.edu>

urban@cbnewsl.att.com (john.urban) (05/15/91)

In article <1991May14.190816.17169@rodan.acs.syr.edu> jstewart@rodan.acs.syr.edu (Ace Stewart) writes:
>
>System: Sun 4/490 running 4.1_PSR_A
>
>Problem: When running a "rm -f" on files that may or may not be in a
>sub-directory, the -f doesn't seem to suppress the error output if a
>file doesn't exist. Script as follows:
>
>----------------
>% ls .Mail/drafts			Listing of directory
>1	2
>3	,1
>,4
>
>% rm -f .Mail/drafts/,*			Remove the , files (temp files)
>%					All okay!  :)
>
>% rm -f .Mail/drafts/,*			Do it again, _problems!_
>No match.
>%
>----------------
>
>What the heck is the -f option there for if it still throws up at you
>if files in a sub-directory don't exist? It works fine if you are _in_
>a that directory (i.e. 'rm -f ,*'  run twice in the sub-directory
>suppresses errors correctly)
>
>Comments/suggestions/help? Am I doing something incredibly stupid?

The 'No match' comes from the csh(1) and not from rm(1).  Try:
% ls -l .Mail/drafts/,*
No match.

%
If you change your shell to the bourne shell (sh) or the korn shell (ksh),
$ ls -l .Mail/drafts/,*  will show:
.Mail/drafts/,*: No such file or directory
$

The rm command is working fine it is the C Shell that is displaying the No match
before rm 'sees' the arguments.


Sincerely,

John Ben Urban

jstewart@rodan.acs.syr.edu (Ace Stewart) (05/15/91)

Many thanx to all the answers; indeed, every one of them said the same
and was correct. What I overlooked was csh's little habits of throwing
up information every once and awhile, and that was the problem.

Briefly: csh announces when the glob cannot expand to anything, and
indeed it is not "rm" that is the problem, it is the csh. The solution
came from wreenm@math.mscs.mu.edu (Michael Wreen) and thanx to him, in
his csh environment command:

	set nonomatch

That seems to solve all of my problems; again thanx to all who
answered directly and posted. All good information, and as far as I
see, all the right answers :)

--Cheers! Ace



-- 
    Ace Stewart | Affiliation: Eastman Kodak Company, Rochester, New York
jstewart@rodan.acs.syr.edu jstewart@sunrise.bitnet jstewart@mothra.cns.syr.edu
   jstewart@sunspot.cns.syr.edu     ace@suvm.bitnet     rsjns@suvm.bitnet