Skip to content
Related Articles

Related Articles

source command in Linux with Examples

View Discussion
Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 31 Jan, 2021

source is a shell built-in command which is used to read and execute the content of a file(generally set of commands), passed as an argument in the current shell script. The command after taking the content of the specified files passes it to the TCL interpreter as a text script which then gets executed. If any arguments are supplied, they become the positional parameters when filename is executed. Otherwise, the positional parameters remain unchanged. The entries in $PATH are used to find the directory containing FILENAME, however if the file is not present in $PATH it will search the file in the current directory. The source command has no option and the argument is the file only. 



source FILENAME [arguments]

Example 1: To pass gfg.txt as an argument which is stored in the home directory and contain list of command i.e. ls, date and time. Each command enlisted in the file will be executed line by line. 


Example 2: To pass a path_name of a file as an argument where, /home/sc/sourcefolder/ is the file directory here. The content of the file is written below: 


echo ” Hello, Welcome to Geeksforgeeks” 
echo “current directory is:” 
echo “Date is:” 



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!