Sourcing a file
suggest changeSourcing a file is different from execution, in that all commands are evaluated within the context of the current bash session. This means that any variables, functions, or aliases defined will persist throughout your session.
Create the file you wish to source sourceme.sh
#!/bin/bash
export A="hello_world"
alias sayHi="echo Hi"
sayHello() {
echo Hello
}
From your session, source the file
$ source sourceme.sh
From henceforth, you have all the resources of the sourced file available:
$ echo $A
hello_world
$ sayHi
Hi
$ sayHello
Hello
Note that the command . is synonymous with source, so you can simply use:
$ . sourceme.sh
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents