简体   繁体   中英

How to print to stderr in fish shell?

In a fish-shell script, how do you print an error message to stderr?

For example, this message should go to the stderr stream rather than the default stdout stream.

echo "Error: $argv[1] is not a valid option"

You can redirect the output to stderr, for example:

echo "Error: $argv[1] is not a valid option" 1>&2

As a reference, here are some common IO-redirections that work in fish*.

foo 1>&2 # Redirects stdout to stderr, same as bash

bar 2>&1 # Redirects stderr to stdout, same as bash

bar ^&1  # Redirects stderr to stdout, the fish way using a caret ^

* The file descriptors for stdin, stdout, and stderr are 0, 1, and 2.
* The & implies you want to redirect to a file stream instead of a file.
* Comparison of redirection in various shells (bash, fish, ksh, tcsh, zsh)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM