Bash AliasingBash ArithmeticBash ArraysBash Associative arraysBash Avoiding date using printfBash Brace ExpansionBash Case statementBash CGI ScriptsBash Chain of commands and operationsBash Change shellBash co-processesBash Color script output (cross-platform)Bash Conditional ExpressionsBash Control StructuresBash Copying (cp)Bash Creating directoriesBash Customizing PS1Bash Cut CommandBash DebuggingBash Decoding URLBash Design PatternsBash File execution sequenceBash File Transfer using scpBash FindBash FunctionsBash getopts : smart positional-parameter parsingBash global and local variablesBash GrepBash Handling the system promptBash Here documents and here stringsBash history substitutionsBash Internal variablesBash IntroductionBash Job ControlBash Jobs and ProcessesBash Jobs at specific timesBash Keyboard shortcutsBash Listing FilesBash Managing PATH environment variableBash MathBash NamespaceBash Navigating directoriesBash on Windows 10Bash ParallelBash Parameter ExpansionBash Pattern matching and regular expressionsBash PipelinesBash PitfallsBash Process substitutionBash Programmable completionBash QuotingBash Read a file (data stream, variable) line-by-line (and/or field-by-field)Bash RedirectionBash ScopingBash Script shebangBash Scripting with ParametersBash Select keywordBash Sleep utilityBash SourcingBash Splitting FilesBash straceBash the cut commandBash true, false and : commandsBash Type of ShellsBash Typing variablesBash Using catBash Using sortBash Using trap to react to signals and system eventsBash when to use evalBash Word splittingNetworking with Bash

Bash Sourcing

From WikiOD

Sourcing a file[edit | edit source]

Sourcing 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, function, or aliases defined will persist throughout your session.

Create the file you wish to source


export A="hello_world"
alias sayHi="echo Hi"
sayHello() {
    echo Hello

From your session, source the file

$ source

From hencefourth, you have all the resources of the sourced file available

$ echo $A

$ sayHi

$ sayHello

Note that the command . is synonymous to source, such that you can simply use

$ .

Sourcing a virtual environment[edit | edit source]

When developing several applications on one machine, it becomes useful to separate out dependencies into virtual environments.

With the use of virtualenv, these environments are sourced into your shell so that when you run a command, it comes from that virtual environment.

This is most commonly installed using pip.

pip install

Create a new environment

virtualenv --python=python3.5 my_env

Activate the environment

source my_env/bin/activate