UNIX Source Command: Read And Execute Commands From File
The source command in Unix/Linux allows you to run commands from a file in the current shell environment. The source command is often used to run shell scripts and shell functions, and can be useful for configuring the shell environment, setting environment variables, and defining shell functions.
Here's an example of how to use the source command:
- Create a file with the commands you want to run. For example:
#!/bin/bash echo "This is a test."Save the file with a
.shextension, such astest.sh. - Make the file executable:
chmod +x test.sh - Run the file using the source command:
source test.shThe output of the file will be displayed in the terminal:
This is a test.
./ command, the changes are only temporary and are not saved after the script has completed.