What is a Bash Source Command
Here you will find out:
- what a bash source command is and its syntax
- how to use the source command
- when DiskInternals can help you
Are you ready? Let's read!
What is a bash source command used for?
If you run Linux then you definitely know this command. Otherwise - you need to meet it! The bash source command reads and launches instructions that are given from the file that is specified as an argument in the shell environment. You can use it to load in shell scripts: variables, functions and configuration documents.
In simple terms, this built-in feature is called to load any feature file(as a parameter) into the current shell script or command prompt.
The syntax for the source command
The syntax is as follows:
In the example above, you can see the dot (.) - it is called a period and this is equal to the source bash script.
It will only read and execute commands from a given filename in the current shell enviroment. The entries in $path are used to look up for the directory containing filename.
In case if filename is not the full path of the file, the command searches for the selected file in the directory specified by the $path.
Again, if the file is still not found in $path - the current directory will be checked.
What if some arguments exist? It will be encountered as positional parameters to the filename.
The exit status of the source command executed: 0 - if the asked and if the file filename exist, and 1 - if the filename not found (doesn’t exist).
Examples of using the source command
Read variables from a file
As you can guess, using bash source command you can read variables from a file. Yes, this command can be useful for different purpose and to read variables from a file, run this bash syntax: variable=value.
Using source command to read the configuration file, you will get:
Output:
Import a script function
To import a script function - it is the main purpose of the source command usage. It is helpful to update the script function - so you can use existing shell functions more efficiently.
Let’s see how it works:
First, you need to create a new script file. Input the following content:
Now you need to create another script to import your printUser function. How can you do that? Well, that is why the source command exists:
Now, it is time to assign the correct permissions to the file to be launched. No need in execute permissions on the file that contain the features to be imported:
As the output you will see the name of the current user.
About Exit Status
Every Linux or Unix command executed by a shell script or user has an exit status. The exit status can be called an integer.
This command returns the status of the last command executed in filename; if it cannot read filename it fails.
An exit status of 0 indicates that the command was successfully executed without any errors. A non-zero (1-255 value) exit status indicates that the command failed.
Open Linux files from Windows
DiskInternals Linux Reader is a popular free software product and it is still non-commercial free software. Starting with version 4.0, Linux Reader Pro provides additional features: access to DVR, Hikvision NAS, ZFS and XFS.
If you are running Linux on a dual-boot or virtual machine, you can use DiskInternals Linux Reader to easily transfer files, read and mount system files. This easy to use, super simple and professional program can help you meet all your data needs.
DiskInternals Linux Reader there is to give you secure, read-only access to the source drive without any hindrance.
Related articles
- About a bash date command
- How to Access Linux Ext2 or Ext3 on Windows
- How to Access Ext4 from Windows
- How to Mount Ext4 on Windows for Free
- Mount Linux Drive on Windows for Free
- Bash Script: All You Need to Know
- An Algorithm: How to Create Bash While Loop
- Linux Shell: What You Need to Know at First
- 5 Basic Shell Script Examples for Your First Script
- Bash: How to Check if the File Does Not Exist
- Bash Time Command on Linux
- How to use bash get script directory in Linux
- How to Check Bash String Equality
- How to Use Linux Wait Command
- Bash: How to Loop Through Files in Directory
- 20 Examples of Bash Find Command
- Bash Cat Command in Examples
- Bash Script SSH: How to Use It
- Bash: A Script For User Input
- Linux ZSH: the basic you need to know
- Basic of Grep in Linux Shell Script
- Shell Script Cut: Basic You Need to Know
- Bash: How to Check if String Not Empty in Linux
- Bash: how to split strings in Linux
- Linux: Sudo in Bash Scripts
- Hello World Script in Bash
- A Linux bin/bash Shell
- Linux: New Line in Shell Script
- Linux: Bash String Ends With
- Linux: Bash Printf Examples
- Linux: Bash First Line
- Linux: $0 in a Shell Script
- Linux: A Bash Startup Script
- Linux: Write a Shell Script
- Shell Script: Replace String in File
- A crontab service shell script
- Bash and sh: is there any difference
- A Bash Dirname Command
- A Bash to Loop through Lines in File
- Linux: A Bash Linter
- A Bash Nested Loop
- A Bash Test Command
- Use a Shell Script to Send an Email
- A Bash Status of Last Command
- Linux: A Bash Basename Command
- Using Bash to Write to a File
- About Bash Language
- Bash for Loop in One Line
- AWK in a Bash Script
- Learn about useful bash scripts
- Learn about systemd startup script
- About chaining bash commands
- Learn about a bash error code
- Using a bash tee command
- About a bash export command
- Learn about a bash wait command
- Arch Linux install script
- About advanced bash scripting
- To run a shell script in Dockerfile
- About a bash UNTIL loop
- Learn about C shell script
- Learn about Korn shell scripting
- Using /usr/bin/env command
- Whether bash waits for command to finish
- Using bash if 0
- Using && in an IF statement in bash
- If you want to run shell script in background
- The disk you inserted was not readable by this computer error
- Learn about SFTP in bash scripting
- Learn to run Perl script in Linux
- Examples of using the Expect
- Copy command in shell scripts
- Shell script usage
- Install Oracle Database
- Here is everything you need to know about Bash for Windows
- Guide in Pictures
- How to Use Shell Script Sleep Command
- A Bash Multiline Command




