Source Command in Linux with Examples
# Source Command in Linux
The `source` command is a Bash built-in command that executes the content of a given file in the current shell environment. It is usually used to execute a shell script in the current shell without creating a child process. It is especially useful when used in combination with shell variables, functions and aliases. This command does not create a new process but instead it runs the commands in the current shell process.
The `source` command can be used to execute any number of commands from a single file. This makes it quite versatile, as it can be used to create custom scripts and functions, or to include custom environment variables in the current shell. It can also be used to set aliases, which can be used to quickly run commands or even to set up custom environment variables.
The source command is also highly useful when used in conjunction with shell scripts. By using the `source` command, shell scripts can be executed within the same shell as the script itself, rather than spawning a new process. This can help to ensure that any variables or functions that are defined in the script are available in the current shell, as well as any environment variables that may have been set by the script.
Overall, the `source` command is a very useful tool for managing your shell environment and executing scripts within the current shell process. It is especially useful for creating custom functions, aliases and environment variables, as well as for executing shell scripts without spawning a new process.
Worried About Failing Tech Interviews?
Attend our webinar on
"How to nail your next tech interview" and learn
Founder, Interview Kickstart
Our tried & tested strategy for cracking interviews
How FAANG hiring process works
The 4 areas you must prepare for
Register for Webinar
How you can accelerate your learnings
The source command in Linux is used to execute commands from the specified file in the current shell environment.
It is an internal command which is used to execute the commands from the specified file in the current shell environment. Syntax: source filename.
$ source my_commands.sh
This command will execute the commands which are present in the file my_commands.sh in the current shell environment.