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 address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc Description: OpenPGP digital signature