how.wtf

How to source shell scripts in Fish

· Thomas Taylor

There may be a use case to source a general sh or bash script in fish. For example, if a function is present in a script file that needs to be sourced, fish cannot execute the script because sh functions are not natively supported.

How to source general scripts in fish

Sourcing general scripts in fish is trivial with a plugin named bass. Using a preferred package manager, bass can be installed and used to source scripts.

1# variables.sh
2
3example(){
4  export VAR_NAME=test	
5}
6example
1source ./variables.sh

Output:

1from sourcing file ./variables.sh
2source: Error while reading file “./variables.sh”

Using bass:

1bass source ./variables.sh
2echo $VAR_NAME

Output:

1test

#Linux  

Reply to this post by email ↪