The built-in bash source command reads and executes the content of a file. If the sourced file is a bash script, the overall effect comes down to running it. We may use this command either in a terminal or inside a bash script. To obtain documentation concerning this command, we should type help source in the terminal.
Mar 18, 2024
People also ask
How to source a file in shell script?
A file is sourced in two ways. One is either writting as source <fileName> or other is writting as . ./<filename> in the command line. When a file is sourced, the code lines are executed as if they were printed on the command line.
How do I input a file into bash script?
To elaborate, we pass the filename as an argument and then read the contents of the file inside the Bash script. When we pass arguments to a Bash script through the command line, the first argument is usually indicated as $1, the second argument as $2, and so on. On the other hand, $0 indicates the filename.
How do I access a file in bash script?
The simplest way to open a file in Bash is to use the cat command. The cat command prints the contents of files without having to open them for editing. The output shows the MyFile content.
How to execute a source file in Linux?

Linux source Command

1
The source command can be used to read a file and treat its content as a set of commands to execute. ...
2
Let's look at the basic syntax: $ source FILENAME [arguments] $ . ...
3
When we run a script using the source command, all the commands are executed in the same shell.
Jun 6, 2020 · The source command reads and executes commands from the file specified as its argument in the current shell environment.
Jun 12, 2020 · Set variables and import functions. You can use source to "import" a file into your shell environment, just as you might use the include keyword ...