On 10/19/07, Myrddin Emrys <[EMAIL PROTECTED]> wrote:
> On 10/18/07, Philip Ganchev <[EMAIL PROTECTED]> wrote:
> > The trouble is the 'noclobber' option in the shell that shall not be
> > named. It makes the '>' operator modal, so when people write '>' they
> > expect something different if they are used to having the option set
> > than if they are not.
>
> Modality isn't quite as bad as all that, since Fish has the facilities for
> excellent just-in-time help. Whenever fish misbehaves for me, it tells me
> why, and often exactly where I need to go to figure it out.
>
> # echo foo > bar
> Error: file exists, and noclobber is set. Use !> to overwrite the file, or
> type help noclobber for more information.
>
Unconvincing - if noclobber was off in the above example you would get
no help (and no file ;-).

But the real reason that modality is very bad lies in shell scripts.
Remember that the shell is not always used in a tight type-execute
feedback loop.  Someone writes a script that works for him in fish
dialect A (noclobber off); 2 years later someone other will run the
script under fish dialect B (noclobber on) and will have no idea why
the script didn't work.

To avoid this, you will have to remember to specify all dialect
options at the beginning of every script, and even then people would
get surprises when they cut-and-paste between scripts and the command
line.

Sadly, the above scripts breakage scenario is bound to occur once now,
if we change the definition of ">".  But in the long term, we will be
better off after the change.
Perhaps we can ease the compatibility problem with a transition plan:

0. Now: Allow ">?" or "?>" and ">!" or "!>" to explicitly mean
noclobber, and encourage people to rewrite scripts.
1. Next version: warn that behaviour will change when ">" is used with
an existing file.
   Optional: warn for any use of ">" in scripts?
2. Post-next version: change behaviour of ">" to mean ">?".
3. Far future: optionally remove ">?" to avoid two ways to spell the same thing?

Step 1 could be done together with 0 if we are eager and the warning
is mostly harmless (e.g. stderr and only if it goes to a terminal?).

But step 3 would discourage rewriting scripts in step 1.  I say we
should leave ">?" legal forever because it looks good in scripts,
explicitly hinting to people who come from other shells that we mean
noclobber.  Perhaps ideally we should transition to ">?" and ">!"
only, removing ">" altogether, but we can't afford it:
* It would surprise people who assume ">" works somehow in all shells!
* It would be inconvenient to type all the time.
* It would lose the safety benefit of making the shortest operator ">"
the noclobber one, which is the main reason we want to make a change
at all.

Two side notes:

* ">?" and "?>" both conflict with wildcard syntax.  But I think the
danger of someone writing "ls ?>one-letter-files" or "ls>?.out" are
negligable, especially the later (I've never seen anyone redirect to a
glob, mainly because it's undefined when there are multiple matches).

* What exactly should ">"/">?" do when the file exists?  Just failing
is good for a single command (because we can check the redirection
before we exec the commands) but perhaps not friendly enough in the
middle of a script or loop.  Perhaps fish should stop and ask the user
for confirmation, if stdin/stderr go to a terminal?

--
Beni Cherniavsky <[EMAIL PROTECTED]> (I read email only on weekends)


-- 
Beni Cherniavsky <[EMAIL PROTECTED]> (I read email only on weekends)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to