Hoi.
[2020-01-03 21:58] Doug McIlroy <doug(a)cs.dartmouth.edu>
I'm interested in the possible motivations
for a redirection to be
a simple command.
I use it to truncate a file to zero length.
Or to create (an empty) file.
Thanks for the replies.
My question was not about the use cases for ``>file'' but *why*
it was made a simple command. Let me explain:
One creates an empty file or truncates a file with:
file
why not with:
:>file
?
To me it looks to be the more sensible ... more regular way.
IO redirections for the shell itself could be made with:
exec >file 5>&
no matter if ``>file'' is a simple command or not. Because of
``exec'' the line is valid syntax (although the grammer probably
was retro-fitted), and the manpages (mksh, bash, heirloom sh) all
document exec without a command as a separate case (and the code
probably handles it as a separate case as well), thus nothing is
gained here from making ``>file'' a simple command.
This is what wonder about: Why make ``>file'' a simple command,
when -- as far as I can currently see -- there is no reason to do
so, as all uses could have been achieved in more regular ways as
well?
So, was it rather by accident and it settled or is there something
I don't see yet? Came `:' later in development, for instance, or
was it special in a way that it couldn't be used to create and
truncate files? Or is there even some clever design that I haven't
understood yet? Are there use cases that can only be achieved with
``>file'' but not with ``:>file''?
meillo