Repository navigation
Description
I propose removing the caret (^) as a redirector for stderr in fish 3.0.
Reason 1: This is surprising for users of other shells and may lead to data loss
There are many commands using the caret on the command line for special purposes, e.g. git (see #1873). While some special handling has been introduced to reduce the need for quoting (see Reason 2), this does not help in all cases, e.g. git log ^refA refB will create a file refA containing the error message of git.
Many other programs use ^, too, for me the most notable problem is grep.
I often use the command dpkg -l|grep -v ^ii to check for problems with not fully installed or purged Debian packages. In fish this prints nothing, and grep's error message is sent to the new file ii.
Or I use ps auxww|grep ^theuser to quickly find processes of some users.
Or grep ^http someconfigfile to see if the config file contains a setting about httpserver or httpproxy or ...
While this often just results in a stray file (which is already bad enough), this can easily overwrite existing files, because sometimes I am looking for something where a file of the same name exists, e.g. Makefile targets (which luckily can often be rebuilt), or filtered output of ls, e.g. ls | grep -v ^README to show me everything but README (which is now overwritten) and various README.foo files. Or ls | grep -v ^access.log | grep -v ^error.log to hide the current and rotated web server log files and see what other files are present. Yes, I could add quotes and I should add a backslash in front of the dot in the regexp, but I really don't expect a file accessblog here, so I don't do it in interactive use.
Reason 2: Workarounds have been introduced, but they introduce even more surprising behavior.
To workaround the problem in git (#1873), the handling of ^ was changed to be different than the handling of >, so echo foo^bar prints foo^bar, but echo foo ^ bar prints foo and creates an empty file bar. This is different from e.g. echo foo>bar and echo foo > bar which both do the same thing.
The need for this workaround indicates that using the caret as a redirection character is problematic.
Reason 3: The law of orthogonality (https://fishshell.com/docs/current/design.html#ortho)
^ is just a shortcut for 2>, so this syntax saves only a single character.
The user still has to know the difference between stdout and stderr to use this feature.
The user still has to know about file descriptors to redirect both, stdout and stderr, to the same file with echo Hello > all_output.txt ^&1.
Activity
mqudsi commentedon Sep 10, 2017
I would be on board with this. It's just not a feature worth having.
ridiculousfish commentedon Sep 11, 2017
I like this too.
zx8 commentedon Sep 13, 2017
Wow, I thought I was the only one who considered this a misfeature!
I'm very much in favour of its removal as well.
krader1961 commentedon Sep 14, 2017
FWIW, I agree this "feature" should be removed. But note that it doesn't affect just
^/a/pathto redirect stderr to /a/path. It also affects^| a_command. We have two such uses of the latter in the fish project: share/completions/apm.fish and share/functions/__fish_print_make_targets.fish. That there are only two such instances in the fish code suggests that use case is relatively rare. Nonetheless it is another use of the feature which will be broken if we implement this change.ThomasAH commentedon Sep 14, 2017
^|is nice for some situations, but there are already some alternative ways to do this:if apm -h ^| string match -q "*Atom Package Manager*"can be changed to
if apm -h 2>&1 | string match -q "*Atom Package Manager*"make -C $directory -d g1 -rn >/dev/null ^| awk ...can be changed to
make -C $directory -d g1 -rn 2>&1 >/dev/null | awk ...If some really needs to print stdout and just wants to pipe/filter stderr, both can be swapped, e.g.:
If above syntax is considered too complicated, the behaviour of
|could be adjusted to match the behaviour of>by allowing file descriptors, so2|would pipe stderr. This is more consistent, allows piping of other file descriptors, and accidents are far less likely to cause data loss, because e.g.grep foo 2|grep barwill not clobber existing files.mqudsi commentedon Sep 14, 2017
There's already a good workaround for it, one that is even less likely to be triggered by accident.
I think it's a highly underrated feature, and I don't think any other "modern" shell makes it this easy.
[-]RFC: Remove caret (^) as redirector for stderr[/-][+]Remove caret (^) as redirector for stderr[/+]scooter-dangle commentedon Feb 15, 2018
What's fish's story on deprecation warnings? I pretty liberally use
^/dev/nullwhen I intend to ignore errors. (Although it will be pretty annoying to get a deprecation notice on stderr if I'm already explicitly ignoring errors for a particular command/function.)ridiculousfish commentedon Apr 1, 2018
The 3.0 release is making these sort of changes without a deprecation phase, in part for the reason you say
Remove caret redirection
Use traditional redirection for stderr (#58)
lilyball commentedon Apr 9, 2018
No deprecation phase is problematic because it means existing scripts will simply break without warning. This apparently includes fisherman and at least one fisherman plugin.
Could we at least add a deprecation phase for
masterwhich we then turn off when releasing 3.0? That way people testing onmastercan try and at least flag shared components (like fisherman) that need to be updated.8 remaining items
Use standard sh-style redirection for stderr (#416)
jorgebucaran commentedon Sep 18, 2018
👏 Good job everyone and thank you, @ThomasAH for getting the ball rolling on this.
Replace caret redirection
Use 2> instead of ^ for stderr redirection.
adeftu commentedon Jan 4, 2019
Issue is marked with fish 3.0.0 milestone and closed. However current 3.0.0 version does not include it.
floam commentedon Jan 4, 2019
It's hidden behind a feature flag,
stderr-nocaret.Use "2>" to redirect stderr instead of the deprecated "^"
Quit recommending caret redirection
ron-wolf commentedon Nov 12, 2019
@floam Doesn’t that kind of defeat the purpose? Either run into weird behavior with
^—which is un-fish-like for the reasons @ThomasAH mentioned above—or add an extra line to your config files, to handle your otherwise smooth shell’s one weird behavior.faho commentedon Nov 12, 2019
@ron-wolf The feature flag is purely a transition thing, and will be removed in a future version of fish.
Remove deprecated operator in Fish 3.1
Update fish prompt to not use the caret since it's deprecated
Update fish prompt to not use the caret since it's deprecated
faho commentedon Jul 27, 2022
For posterity: All code for the
^redirection has been removed in fish 3.5.0, after it was disabled by default in fish 3.3.0.The feature flag remains available to check, but it will always return true. See #8857 for more information.