What is a source script?

What is a source script?

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.

When should you source a shell script?

Sourcing a script will run the commands in the current shell process. Executing a script will run the commands in a new shell process. Use source if you want the script to change the environment in your currently running shell. use execute otherwise.

How to define a shell script to be sourced not run?

Under bash, ${BASH_SOURCE[0]} will contain the name of the current file that the shell is reading regardless of whether it is being sourced or executed. By contrast, $0 is the name of the current file being executed. -ef tests if these two files are the same file.

What’s the difference between source, Exec and./ script?

When the end of the script file is encountered, the new shell exits. Any changes in the new shell caused by the script are lost when the shell exits. /home/user/sample/script/test contains… source execute a shell script within the context of the current shell.

How to make a script run as a program?

Open a new terminal session or type source ~/.bashrc in your terminal to apply. Then simply use the new name to start the script. Right-click the file and select Properties. Go to the permissions tab, then tick the box Execute: [ ] Allow executing file as program or in Nautilus Program: [ ] Allow this file to run as a program in Thunar.

Where does the source of a script come from?

If you have a ~/bin directory in your $PATH, you have A inside this directory. It sources the script ~/bin/lib/B. You know where the included script is relative to the original one, in the lib subdirectory, but not where it is relative to the user’s current directory.