[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: option abbreviation exceptions
From: |
Andrew McGill |
Subject: |
Re: option abbreviation exceptions |
Date: |
Tue, 6 Jan 2009 07:31:46 +0200 |
User-agent: |
KMail/1.9.9 |
On Tuesday 30 December 2008 15:00:18 Eric Blake wrote:
> According to Pádraig Brady on 12/30/2008 2:46 AM:
> >> Usage: truncate [OPTION]... [FILE]...
> >
> > Is supporting stdin a useful enhancement?
er ...
> > Maybe if you can get the shell to open
> > different files based on some condition,
> > though again that seems a little contrived.
>
> if cond ; then
> foo=file1
> else
> foo=file2
> fi
> truncate -s0 <$foo
This redirection is wonderful, but entirely counter-intuitive. By convention
stdout is where writes occur, stdin is where reads occur. Modifying the file
given as stdin is just a little unexpected.
For good measure (all?) shells open stdin as read-only, which makes the
operation fail -- ftruncate(0,0) gives "invalid argument". The redirection
you need for a writable stdin under bash seems to be this one:
truncate -s$SIZE 0>>$foo
&:-)
- Re: option abbreviation exceptions,
Andrew McGill <=