See previous question, How to pipe on a condition in Bash. I’m interested in the same construct for Fish, i.e. shorthand for:
set check 0
if test $check = 1
printf "foonbarnbazn" | string match --regex ^f
else
printf "foonbarnbazn" | string match --regex ^b
end
This can be done via:
set check 0
printf "foonbarnbazn" | if test $check = 1
cat | string match --regex ^f
else
cat | string match --regex ^b
end
Or, if you need to pipe stdin to a variable:
set check 0
printf "foonbarnbazn" | begin
read --local --null input
if test $check = 1
string match --regex ^f $input
else
string match --regex ^b $input
end
end