Bash Script
Think of a script for a play, or a movie, or a TV show. The script tells the actors what they should say and do. A script for a computer tells the computer what it should do or say.
In the context of Bash scripts, Bash scripts tells the Bash shell what it should do.
A Bash script is a plain text file which contains a series of commands.
Anything you can run normally on the command line can be put into a script and it will do exactly the same thing. Similarly, anything you can put into a script can also be run normally on the command line and it will do exactly the same thing.
It is convention to give files that are Bash scripts an extension of.sh (myscript.sh for example).
How Bash script work
Program and Process
In the realm of computer, a program is a blob of binary data consisting of a series of instructions for the CPU and possibly other resources (images, sound files and such) organised into a package and typically stored on hard disk.
A process is a running instance of a program.
When running a program, a copy of a program (instructions and resources) is copied from the hard disk into working memory (RAM)
Some space in RAM are allocated for the process to store variables (to hold temporary working data) and a few flags to allow the operating system (OS) to manage and track the process during it's execution.
There could be several processes representing the same program running in memory at the same time.
For example, We could have two terminals open and be running the command cp in both of them.
In this case, there would be two cp processes existing the system.
"Running a bash script" and "executing the bash script" have identical meaning.
Path variable
Commanding code and its response 1: echo $PATH
CCAIT.1 shows the effect of commanding code echo $PATH.
When you type a name on the command line, Bash tries to find it in a series of directories stored in a variable called $PATH.
The directories are separated by ":".
Bash only looks in those specific directories and does not consider sub directories or your current directory.
Bash will look through those directories in order and execute the first instance of the program or script.
The $PATH variable is an individual user variable so each user on a system may set it to suit themselves.
The $PATH variables allows us to have several different versions of a program installed. We can control which one gets executed based on where it sits in our $PATH.
The $PATH variables allow for convenience. The first directory for myself is a bin directory in my home directory. This allows user to put scripts and programs there and can use them no matter where user is in the system by just typing their name.
The $PATH variables increases safety. For example, a malicious user coud create a script called ls, which deletes everything in your home directory. However, as long as it is not in your $PATH, that will not happen.
If a program or script is not in one of the directories in user's $PATH, then user need to tell Bash either an absolute or relative path in front of the program or script name.
dot ( . ) is actually a reference to your current directory.
Assuming this script is in home directory, an absolute path maybe
/home/ryan/myscript.sh
SheBang (#!)
#!/bin/bash is the first line of the script.The has exclamation mark (#!) character sequence is referred to as the Shebang.
Following it is the path to the interpreter (or program) that should be used to run (or interpret) the rest of the lines in the text file.
For Bash scripts, it will be the path to Bash, but there are many other types of scripts and they each have their own interpreter.
[0]
https://ryanstutorials.net/bash-scripting-tutorial/bash-script.php