When you log into a Linux shell, you inherit a specific working environment. An environment, in the context of a shell, means that there are certain variables already set for you, which ensures your commands work as intended. For instance, the PATH environment variable defines where your shell looks for commands. Without it, nearly everything you try to do in Bash would fail with a command not found error. Your environment, while mostly invisible to you as you go about your everyday tasks, is vitally important.

There are many ways to affect your shell environment. You can make modifications in configuration files, such as **~/.bashrc** and **~/.profile**, you can run services at startup, and you can create your own custom commands or script your own Bash functions.

Add to your environment with source

Bash (along with some other shells) has a built-in command called **source**. And here’s where it can get confusing: **source** performs the same function as the command **.** (yes, that’s but a single dot), and it’s not the same **source** as the **Tcl** command (which may come up on your screen if you type **man source**). The built-in **source** command isn’t in your **PATH** at all, in fact. It’s a command that comes included as a part of Bash, and to get further information about it, you can type **help source**.

The **.** command is POSIX-compliant. The **source** command is not defined by POSIX but is interchangeable with the **.** command.

More on Bash

According to Bash **help**, the **source** command executes a file in your current shell. The clause “in your current shell” is significant, because it means it doesn’t launch a sub-shell; therefore, whatever you execute with **source** happens within and affects your current environment.Before exploring how **source** can affect your environment, try **source** on a test file to ensure that it executes code as expected. First, create a simple Bash script and save it as a file called **hello.sh**:

#!/usr/bin/env bash
echo "hello world"

#bash #bash functions. #posix

Import functions and variables into Bash with the source command
3.30 GEEK