If you want to test some expressions for using in a script, but don't want to run a whole script, you can simply put the command(s) to test in a regular text file, save it as "test", or whatever you want, and then 'source' the text file with the command(s).........
To source a file, you run the command:
source ./test
NOTE: You must use a valid path to the file, such as a full path, or use the shortcut path of
./ to represent the current directory..........
There is shortcut command for source when sourcing a file, which is to replace the word 'source' with a single dot, like so:
. ./test
When sourcing a file, you do not need to make it excecutable with the 'chmod' command, nor do you need to add the "shebang" line (#!...) at the top of the file......
This is a great way to test long or complicated commands without having to type it on the command line, or to refine commands by changing certain commands and testing them, to make sure they work.........
PS: This method is also used in scripts to add variables or extra commands/functions to the script, thus making a script modular................You save certain commands (usually in the form of functions) or variables, which may be commonly used among various scripts, into a separate file and then source that file early in the script............