How to Use Linux’s source Command to Refresh Environments and Run Scripts
This guide explains the Linux source command, covering its syntax, how to refresh the current shell environment, execute scripts within the same session, import functions, and read variables from other scripts, with practical examples and command-line illustrations.
Introduction
The source built‑in shell command reads and executes a file in the current shell session, allowing you to modify or preserve environment variables without spawning a new process.
Syntax
The basic form is: source FILENAME [ARGUMENTS] You can also use the shorthand . (dot) instead of source:
. FILENAME [ARGUMENTS]1. Refreshing the Current Shell Environment
Define an alias in ~/.bashrc and reload it with source: echo "alias ll='ls -al'" >> ~/.bashrc Then refresh: source ~/.bashrc After reloading, the ll alias lists all files, including hidden ones.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
