简体   繁体   中英

Fish while & if with a pipeline condition : Command substitutions not allowed

Consider this brief conversation with fish:

while (echo d | mail); sleep 1; end

fish: Command substitutions not allowed
while (echo d | mail) ; sleep 1 ; end
      ^

how can I correct my while loop?

More generally: do I understand right that the problem is something like: the while CONDITION is a command, but fish only allows (command substitution) for parameters to a command, not the command itself?

So I think my question for both if and while could be: how do I write a pipeline as the CONDITION?

This can be written simply as:

while echo d | mail; sleep 1; end

In fish, as in other shells, command substitutions takes the output of the inner command, and uses it as arguments to the outer command. The exit status is discarded, which is why fish disallows them as the condition in loops.

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