Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fish shell: how to exit on error (bash set -e)

On bash you can use set -e inside a script in order to exit on error:

set -e
cd unexisting-folder
echo "this line will not be printed"

But on fish shell set -e is used to erase variables:

set FOO bar
set -e FOO
echo {$FOO} # prints newline

What is the equivalent of Bash set -e on Fish?

like image 535
mdesantis Avatar asked Nov 09 '13 12:11

mdesantis


People also ask

How do you use fish instead of bash?

If you wish to use fish (or any other shell) as your default shell, you need to enter your new shell's executable /usr/local/bin/fish in two places: add /usr/local/bin/fish to /etc/shells. change your default shell with chsh -s to /usr/local/bin/fish.

Is fish compatible with bash?

Regular bash scripts can be used in fish shell just as scripts written in any language with proper shebang or explicitly using the interpreter (i.e. using bash script.sh ). However, many utilities, such as virtualenv, modify the shell environment and need to be sourced, and therefore cannot be used in fish.

How do I run a fish shell script?

To be able to run fish scripts from your terminal, you have to do two things. Add the following shebang line to the top of your script file: #!/usr/bin/env fish . Mark the file as executable using the following command: chmod +x <YOUR_FISH_SCRIPT_FILENAME> .


1 Answers

There's no equivalent of this in fish. https://github.com/fish-shell/fish-shell/issues/805 spend a little time discussing what a fishy version of this might look like.

If the script is short, prefixing each line with and might not be too bad:

cp file1 file2
and rm file1
and echo File moved
like image 71
ridiculous_fish Avatar answered Sep 21 '22 00:09

ridiculous_fish