mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-25 23:21:15 -03:00
Let "return" exit a script (#8148)
Currently, if a "return" is given outside of a function, we'd just throw an error. That always struck me as a bit weird, given that scripts can also return a value. So simply let "return" outside also exit the script, kinda like "exit" does. However, unlike "exit" it doesn't quit an interactive shell - it seems weird to have "return" do that as well. It sets $status, so it can be used to quickly set that, in case you want to test something.
This commit is contained in:
22
tests/checks/return.fish
Normal file
22
tests/checks/return.fish
Normal file
@@ -0,0 +1,22 @@
|
||||
#RUN: %fish -C 'set -l fish %fish' %s
|
||||
# Some tests of the "return" builtin.
|
||||
|
||||
$fish -c 'return 5'
|
||||
echo $status
|
||||
# CHECK: 5
|
||||
|
||||
$fish -c 'exit 5'
|
||||
echo $status
|
||||
# CHECK: 5
|
||||
|
||||
$fish -c 'echo foo; return 2; echo bar'
|
||||
# CHECK: foo
|
||||
# but not bar
|
||||
echo $status
|
||||
# CHECK: 2
|
||||
|
||||
$fish -ic 'echo interactive-foo; return 69; echo interactive-bar'
|
||||
# CHECK: interactive-foo
|
||||
# but not bar
|
||||
echo $status
|
||||
# CHECK: 69
|
||||
Reference in New Issue
Block a user