Skip to content

Instantly share code, notes, and snippets.

@vhbui02
Last active April 28, 2023 15:59
Show Gist options
  • Save vhbui02/7759fddf79b80de4153c33ef1d8750dc to your computer and use it in GitHub Desktop.
Save vhbui02/7759fddf79b80de4153c33ef1d8750dc to your computer and use it in GitHub Desktop.
[eval vs exec] same shjt? no #fish #shell

Example

example.sh

#!/bin/bash
echo "Hello world!"

If we want to execute this script from Fish Shell, we can use either exec or eval

Using exec

exec bash example.sh

Fish Shell replaces itself with the new process - the Bash interpreter running example.sh script. This means that when the script finishes, the Bash interpreter takes over the terminal and Fish Shell is no longer running!

Using eval

eval bash example.sh

Fish Shell stays running, but the output of the command is printed to the terminal as usual. This means that after the script finishes, Fish Shell is still running and we can continue to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment