Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add friendly stdout and stderr redirection &> #6192

Closed
bleepnetworks opened this issue Oct 11, 2019 · 22 comments
Closed

add friendly stdout and stderr redirection &> #6192

bleepnetworks opened this issue Oct 11, 2019 · 22 comments

Comments

@bleepnetworks
Copy link

@bleepnetworks bleepnetworks commented Oct 11, 2019

fish, version 3.0.2
macos mojave 10.14.6 (18G103)
Darwin Kernel Version 18.7.0
xterm-256color
sh -c 'env HOME=$(mktemp -d) fish' <- does not resolve the issue

reproduction:

> ls -l /bogus > output 2>&1
> ls -l /bogus &> output
fish: Expected a command, but instead found a redirection
ls -l /bogus &> output
              ^
>

bash:

$ bash --version | head -n 1
GNU bash, version 5.0.11(1)-release (x86_64-apple-darwin18.6.0)
$ ls -l /bogus > output 2>&1
$ ls -l /bogus &> output
$

bash has supported the '&>' short form since version 4 and zsh supports it as well. '&>' is way easier to remember than 'cmd > file 2>&1', would be great if fish added support for it

@faho
Copy link
Member

@faho faho commented Oct 11, 2019

For those watching along at home, #689 asked for the same thing, but was closed as a duplicate of #110 because that was just titled "Syntax improvements for redirection & pipes". However it was then closed because the only thing that was really asked for was a way to pipe stderr and stdout together, which is now possible with 2>&1 | (i.e. pipe stdout, redirect stderr to stdout).

Personally, I don't think this is useful often enough to warrant yet more syntax, but if anyone else thinks it's important enough to implement, go ahead.

@faho faho added this to the fish-future milestone Oct 11, 2019
@bleepnetworks
Copy link
Author

@bleepnetworks bleepnetworks commented Oct 11, 2019

hi @faho it's one less barrier to adoption of a new shell. if bash and zsh support it why not fish.

I am a long time bash user considering a new shell, and the more changes I have to make to my existing conf files the less likely I am to make the switch.

plus it's a much more intuitive syntax.

@faho
Copy link
Member

@faho faho commented Oct 11, 2019

if bash and zsh support it why not fish.

Fish is neither bash nor zsh. It's different, on purpose.

@bleepnetworks
Copy link
Author

@bleepnetworks bleepnetworks commented Oct 11, 2019

if bash and zsh support it why not fish.

Fish is neither bash nor zsh. It's different, on purpose.

oh sure, but it's still a shell right? so why not make it easier to switch?

@floam
Copy link
Member

@floam floam commented Oct 12, 2019

I think what bash and zsh came up with here is pretty reasonable. Redirecting both stdout and stderr to one place is a common enough task. For a new shell user cmd > file 2>&1 is pretty indecipherable and just ends up as something to be memorized and potentially messed up when they try to recount it each and every time.

cmd &> file is plainly easier and I can't think of something obviously more fishy off the top of my head. As I often say, my view is that being compatible with other shells aids in discoverability and shouldn't be avoided for the sake of being different. We just shouldn't do things other shells do purely for the sake of compatibility.

@ridiculousfish
Copy link
Member

@ridiculousfish ridiculousfish commented Oct 13, 2019

fish has pretty much bought into the bash syntax for redirections already, so I think it makes sense to match this.

@amosbird
Copy link
Contributor

@amosbird amosbird commented Oct 14, 2019

I guess that means we can also support |& ?

@floam
Copy link
Member

@floam floam commented Oct 14, 2019

Since I haven't seen ^> mentioned here yet, in 2013 fish-shell member @xfix preferred ^> over &> when it was suggested in #689.

@ridiculousfish
Copy link
Member

@ridiculousfish ridiculousfish commented Oct 15, 2019

We're moving away from ^ as a stderr redirection (stderr-nocaret feature flag).

@mqudsi
Copy link
Contributor

@mqudsi mqudsi commented Oct 27, 2019

I'm OK with this since & is already a reserved character.

@zanchey
Copy link
Member

@zanchey zanchey commented Oct 30, 2019

Closed by #6206?

@zanchey zanchey removed this from the fish-future milestone Oct 30, 2019
@zanchey zanchey added this to the fish 3.1.0 milestone Oct 30, 2019
@zanchey zanchey removed the RFC label Oct 30, 2019
@faho
Copy link
Member

@faho faho commented Oct 31, 2019

Yep.

@faho faho closed this Oct 31, 2019
@lucasb-eyer

This comment has been minimized.

@krobelus

This comment has been minimized.

@skerit

This comment has been minimized.

@faho

This comment has been minimized.

@skerit
Copy link

@skerit skerit commented Apr 21, 2020

I actually just tried that! But my original line doesn't seem to work anymore.

The original line btw was git diff --quiet HEAD ^&-, which I now changed to git diff --quiet HEAD >/dev/null 2>&1, but that doesn't seem to do the same thing.

Maybe it has something to do with the - closing the file descriptor? Anyway, changing it to &>&- does not work either, that throws an error :/

@faho
Copy link
Member

@faho faho commented Apr 21, 2020

The original line btw was git diff --quiet HEAD ^&-, which I now changed to git diff --quiet HEAD >/dev/null 2>&1, but that doesn't seem to do the same thing.

What happens? What do you want to happen?

Typically closing the file descriptor is strictly wrong (as in the program will fail or crash because of it) or doesn't matter. It fixing things is quite unexpected.

@faho
Copy link
Member

@faho faho commented Apr 21, 2020

Okay, I think I got it. You want to silence just stderr. In that case use 2>/dev/null.

Because the bit that signifies "close the file descriptor" is "&-", not just "-", and the ^ is the old fish-specific way of spelling 2>, stderr.

This entire issue is of no interest to you (and wasn't to the first person to mention ^&- either).

@skerit
Copy link

@skerit skerit commented Apr 21, 2020

Yeah, sorry for taking this so off-topic. It was a shell prompt I found a long time ago. But even when just using 2>/dev/null it doesn't seem to work.

I'll look for another shell prompt, thanks for the help anyway!

@faho
Copy link
Member

@faho faho commented Apr 21, 2020

Yeah, sorry for taking this so off-topic. It was a shell prompt I found a long time ago. But even when just using 2>/dev/null it doesn't seem to work.

Some context would be quite nice, then I might be able to help you.

@skerit
Copy link

@skerit skerit commented Apr 21, 2020

Well, it's getting quite confusing. I installed fish 3.1.0 on another device, and replaced it with 2>/dev/null as you previously said, and it DID work there!

Somehow I seriously broke something in my fish install, but yeah 2>/dev/null does fix the prompt.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants