[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

<> redirection and notations



Folks,

I was mistaken when I said that <> truncated files in ksh. (Maybe it does
in bash? I just got through going through the bash doc.  If so, bash is
wrong... Sigh.)  The ksh book doesn't say it truncates, and experimentation
with ksh shows that indeed it just opens it read/write but does NOT truncate.

I had suggested multiple functions, Alan (I think) said why not just pass
a mode to %open, and then Paul said sometimes one only wants to spoof one
and not the other.  The way to go is to have our cake and eat it too:

Sugar	Meaning		Function	Implementation
-----	-------		--------	--------------
<	open ro		%open-ro	@{ %open r $* }
>	open wo		%open-wo	@{ %open w $* }
>>	open append	%open-app	@{ %open a $* }
<>	open rw		%open-rw	@{ %open r+ $* }
<>!	open rw+trun	%open-rw-trunc	@{ %open w+ $* }
<>>	open rw+app	%open-rw-app	@{ %open a+ $* }

Thus we can either spoof one thing or the whole mess, and we have
access to every way we'd like to open files. (What do folks think of <>! ?
I had first thought about <<> , and then <>< but didn't really like either
of those...)

I admit <> is a little used construct - maybe it's little used because
it was never there? (Which came first ... :-)

Now, as to how to replace <>{...}.  From the discussion, it sounds like we're
going to need a two character glyph or else just %.  I'd rather see a
two character glyph like :: but % will do the trick for me ok too.

Again, I apologize for saying <> truncated in ksh. It does in bash, and I
think bash is broken for doing it that way.  That mistake unfortunately added
unnecessary fuel to the fire.

Arnold