I want to ignore yarn errors using this method
yarn install 2> >(grep -v warning 1>&2)
As I am using fish shell I did figure out that this command has to become yarn install 2> ">(grep -v warning 1>&2)"
to avoid a syntax error
However after one I want to run yarn run postinstall --force
So my command became yarn install 2> ">(grep -v warning 1>&2)" && yarn run postinstall --force
however it seems does not work, yarn run postinstall --force
does not really runs. Command finishes right afteryarn install
finishes.
Any ideas how to fix?
UPDATE: I also want that script to run in bash because this going to execute not just on my local dev machine but also on CD/CI that does not have fish-shell installed..
CodePudding user response:
EDIT: The question was originally tagged as "fish", so this answer assumes you'd want to use fish to run the script.
yarn install 2> >(grep -v warning 1>&2)
This is a bit of an awkward idiom. It pipes the stderr of yarn install
into a process substitution (the >()
syntax, which is like the reverse of its <()
cousin). This creates a temporary file that it will then connect to grep -v
's stdin, which will then get its output redirected to stderr again. The effect is that stderr is filtered and any line containing "warning" is removed.
Really, the reason for this is that it is awkward in bash to pipe stderr but not stdout - see How can I pipe stderr, and not stdout? - this is https://stackoverflow.com/a/15936384/3150338.
In fish, you can just pipe stderr with 2>|
:
yarn install 2>| grep -v warning 1>&2
See e.g.
function printstuff
echo error >&2
echo warning >&2
echo output
echo warning but on stdout
end
printstuff 2>| grep -v warning 1>&2
This will print "error" on stderr, and "output" and "warning but on stdout" on stdout.