Skip to content

no error about wrong >>? redirection operator #8380

Closed

Description

@EmilyGraceSeville7cf

Fish version: 3.3.0 (built from source)
OS version: Linux Mint 20.2 Cinnamon

Documentation lists only the following redirection operators (with arbitrary FD too):

  • To read standard input from a file, use <SOURCE_FILE.
  • To write standard output to a file, use >DESTINATION.
  • To write standard error to a file, use 2>DESTINATION. 1
  • To append standard output to a file, use >>DESTINATION_FILE.
  • To append standard error to a file, use 2>>DESTINATION_FILE.
  • To not overwrite ("clobber") an existing file, use >?DESTINATION or 2>?DESTINATION. This is known as the "noclobber" redirection.
  • As a convenience, the redirection &> can be used to direct both stdout and stderr to the same destination.

But when I run code with:

echo 1 >>? test.txt

I obtain warning: The file 'test.txt' already exists instead smth like Wrong redirection operator used. Of course maybe 1 > is redirected instead of 1 but I think it is unclear even if it's right because no space between first > and second one persists. What about to warn user about this (add this as a feature can be disabled)?

Activity

  1. floam commented on Oct 24, 2021

    @floam
    Member

    maybe 1 > is redirected instead of 1

    It may have escaped the docs but but we do specifically test that it works as intended in our test suite, which is that it appends and also enables the noclobber feature to avoid appending to a file which we don't want to have exist.. which is kind of a strange thing to do but there ya go. This behavior documented in tokenizer.cpp.

    // Note 'echo abc >>? file' is valid: it means append and noclobber.
    // But here "noclobber" means the file must not exist, so appending
    // can be ignored.

  2. EmilyGraceSeville7cf commented on Oct 27, 2021

    @EmilyGraceSeville7cf
    ContributorAuthor

    @floam, please add note about it to docs not to confuse newcomers. :)

  3. ridiculousfish commented on Nov 6, 2021

    @ridiculousfish
    Member

    I added a mention of append and noclobber combined. I tried to simplify the rest a bit to compensate. Thanks for filing.

  4. added this to the fish 3.4.0 milestone on Nov 6, 2021
  5. added
    docs
    on Nov 6, 2021
  6. added a commit that references this issue on Dec 12, 2021
  7. locked as resolved and limited conversation to collaborators on Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions