How to group multiple conditions in an if statement in fish

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
As is, the code below is invalid, because the brackets can not be used like that. if we remove them, it runs fine, and outputs:
true
true
code:
#!/usr/bin/fish
if ( false ; and true ) ; or true
echo "true"
else
echo "false"
end
if false ; and ( true ; or true )
echo "true"
else
echo "false"
end
How to get the functionality indicated by the brackets?
desired output:
true
false
fish
add a comment |Â
up vote
2
down vote
favorite
As is, the code below is invalid, because the brackets can not be used like that. if we remove them, it runs fine, and outputs:
true
true
code:
#!/usr/bin/fish
if ( false ; and true ) ; or true
echo "true"
else
echo "false"
end
if false ; and ( true ; or true )
echo "true"
else
echo "false"
end
How to get the functionality indicated by the brackets?
desired output:
true
false
fish
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
As is, the code below is invalid, because the brackets can not be used like that. if we remove them, it runs fine, and outputs:
true
true
code:
#!/usr/bin/fish
if ( false ; and true ) ; or true
echo "true"
else
echo "false"
end
if false ; and ( true ; or true )
echo "true"
else
echo "false"
end
How to get the functionality indicated by the brackets?
desired output:
true
false
fish
As is, the code below is invalid, because the brackets can not be used like that. if we remove them, it runs fine, and outputs:
true
true
code:
#!/usr/bin/fish
if ( false ; and true ) ; or true
echo "true"
else
echo "false"
end
if false ; and ( true ; or true )
echo "true"
else
echo "false"
end
How to get the functionality indicated by the brackets?
desired output:
true
false
fish
asked Feb 27 at 12:53
hoijui
1217
1217
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
You can use begin and end for conditionals as well:
From fish tutorial:
For even more complex conditions, use begin and end to group parts of them.
For a simpler example, you can take a look at this answer from stackoverflow.
For your code, you just have to replace the ( with begin ; and the ) with ; end.
#!/usr/bin/fish
if begin ; false ; and true ; end ; or true
echo "true"
else
echo "false"
end
if false; and begin ; true ; or true ; end
echo "true"
else
echo "false"
end
ouhh i did not know aboutbeginat all, thanks! maybe also add a link to the docu: fishshell.com/docs/current/commands.html#begin PS: nice answer!
â hoijui
Feb 27 at 14:04
add a comment |Â
up vote
0
down vote
Alternative solution: outsource part of the conditional chain into a function
like so:
#!/usr/bin/fish
function _my_and_checker
return $argv[1]; and argv[2]
end
function _my_or_checker
return $argv[1]; or argv[2]
end
if _my_and_checker false true ; or true
echo "true"
else
echo "false"
end
if false; and _my_or_checker true true
echo "true"
else
echo "false"
end
This makes most sense if the conditions themselves are complex commands.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You can use begin and end for conditionals as well:
From fish tutorial:
For even more complex conditions, use begin and end to group parts of them.
For a simpler example, you can take a look at this answer from stackoverflow.
For your code, you just have to replace the ( with begin ; and the ) with ; end.
#!/usr/bin/fish
if begin ; false ; and true ; end ; or true
echo "true"
else
echo "false"
end
if false; and begin ; true ; or true ; end
echo "true"
else
echo "false"
end
ouhh i did not know aboutbeginat all, thanks! maybe also add a link to the docu: fishshell.com/docs/current/commands.html#begin PS: nice answer!
â hoijui
Feb 27 at 14:04
add a comment |Â
up vote
3
down vote
accepted
You can use begin and end for conditionals as well:
From fish tutorial:
For even more complex conditions, use begin and end to group parts of them.
For a simpler example, you can take a look at this answer from stackoverflow.
For your code, you just have to replace the ( with begin ; and the ) with ; end.
#!/usr/bin/fish
if begin ; false ; and true ; end ; or true
echo "true"
else
echo "false"
end
if false; and begin ; true ; or true ; end
echo "true"
else
echo "false"
end
ouhh i did not know aboutbeginat all, thanks! maybe also add a link to the docu: fishshell.com/docs/current/commands.html#begin PS: nice answer!
â hoijui
Feb 27 at 14:04
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You can use begin and end for conditionals as well:
From fish tutorial:
For even more complex conditions, use begin and end to group parts of them.
For a simpler example, you can take a look at this answer from stackoverflow.
For your code, you just have to replace the ( with begin ; and the ) with ; end.
#!/usr/bin/fish
if begin ; false ; and true ; end ; or true
echo "true"
else
echo "false"
end
if false; and begin ; true ; or true ; end
echo "true"
else
echo "false"
end
You can use begin and end for conditionals as well:
From fish tutorial:
For even more complex conditions, use begin and end to group parts of them.
For a simpler example, you can take a look at this answer from stackoverflow.
For your code, you just have to replace the ( with begin ; and the ) with ; end.
#!/usr/bin/fish
if begin ; false ; and true ; end ; or true
echo "true"
else
echo "false"
end
if false; and begin ; true ; or true ; end
echo "true"
else
echo "false"
end
edited Feb 27 at 13:14
answered Feb 27 at 12:59
Stefan M
8101617
8101617
ouhh i did not know aboutbeginat all, thanks! maybe also add a link to the docu: fishshell.com/docs/current/commands.html#begin PS: nice answer!
â hoijui
Feb 27 at 14:04
add a comment |Â
ouhh i did not know aboutbeginat all, thanks! maybe also add a link to the docu: fishshell.com/docs/current/commands.html#begin PS: nice answer!
â hoijui
Feb 27 at 14:04
ouhh i did not know about
begin at all, thanks! maybe also add a link to the docu: fishshell.com/docs/current/commands.html#begin PS: nice answer!â hoijui
Feb 27 at 14:04
ouhh i did not know about
begin at all, thanks! maybe also add a link to the docu: fishshell.com/docs/current/commands.html#begin PS: nice answer!â hoijui
Feb 27 at 14:04
add a comment |Â
up vote
0
down vote
Alternative solution: outsource part of the conditional chain into a function
like so:
#!/usr/bin/fish
function _my_and_checker
return $argv[1]; and argv[2]
end
function _my_or_checker
return $argv[1]; or argv[2]
end
if _my_and_checker false true ; or true
echo "true"
else
echo "false"
end
if false; and _my_or_checker true true
echo "true"
else
echo "false"
end
This makes most sense if the conditions themselves are complex commands.
add a comment |Â
up vote
0
down vote
Alternative solution: outsource part of the conditional chain into a function
like so:
#!/usr/bin/fish
function _my_and_checker
return $argv[1]; and argv[2]
end
function _my_or_checker
return $argv[1]; or argv[2]
end
if _my_and_checker false true ; or true
echo "true"
else
echo "false"
end
if false; and _my_or_checker true true
echo "true"
else
echo "false"
end
This makes most sense if the conditions themselves are complex commands.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Alternative solution: outsource part of the conditional chain into a function
like so:
#!/usr/bin/fish
function _my_and_checker
return $argv[1]; and argv[2]
end
function _my_or_checker
return $argv[1]; or argv[2]
end
if _my_and_checker false true ; or true
echo "true"
else
echo "false"
end
if false; and _my_or_checker true true
echo "true"
else
echo "false"
end
This makes most sense if the conditions themselves are complex commands.
Alternative solution: outsource part of the conditional chain into a function
like so:
#!/usr/bin/fish
function _my_and_checker
return $argv[1]; and argv[2]
end
function _my_or_checker
return $argv[1]; or argv[2]
end
if _my_and_checker false true ; or true
echo "true"
else
echo "false"
end
if false; and _my_or_checker true true
echo "true"
else
echo "false"
end
This makes most sense if the conditions themselves are complex commands.
answered Feb 27 at 16:08
hoijui
1217
1217
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426928%2fhow-to-group-multiple-conditions-in-an-if-statement-in-fish%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password