GNU bug report logs - #7463
truncate

Previous Next

Package: coreutils;

Reported by: Rupert Bruce <rbruce <at> nearshore.biz>

Date: Mon, 22 Nov 2010 14:39:01 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #16 received at 7463 <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Rupert Bruce <rbruce <at> nearshore.biz>
Cc: 7463 <at> debbugs.gnu.org
Subject: Re: bug#7463: truncate
Date: Mon, 22 Nov 2010 08:48:29 -0700
[Message part 1 (text/plain, inline)]
On 11/22/2010 07:41 AM, Rupert Bruce wrote:
> truncate (GNU coreutils) 7.4
> 
> Unexpected behavior:
> 
> $ ls -l
> total 0
> $ truncate --size 0 *.log
> $ ls
> *.log

Thanks for the report.  However, this is not a bug, but how the shell
works.  By default, if a shell glob has no matches (in your case, there
are no files ending in .log in the current directory), then the glob is
passed as-is to the child process.  And truncate assumes that when given
a file name that it should create that file.

> 
> I would expect "truncate --size 0 *.log" to truncate any files ending
> with ".log"; instead I get a new file called "*.log"

Then your expectations need to be refined in light of standardized shell
globbing behavior.

Also, since you mentioned you use bash, you can change your shell
defaults.  For example, 'shopt -s failglob' would make your above
command abort because no .log files were present, rather than passing
the unexpanded glob on as a filename.  Likewise, 'shopt -s nullglob'
would make a non-matching glob silently result in no output (use with
caution; things like 'cat *.log' become a much different beast when
nullglob is enabled).

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 14 years and 182 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.