
To create a bash script file, open any code editor and create a new file
Add the shebang (#!) at the top of the file. It tells the systems that this file should be interpreted as a Bash Script whose interpreter is located at the path after the shebang.
The Shebang should be on the first line, with no spaces between them.
Shebang line is #!/bin/bash
write your bash script under the shebang and save the file with the .sh extension. Let's save it as hello.sh
#!/bin/bash
echo Hello World!
Now to give execute permission to this file, to run it as a script. run
chmod u+x hello.sh
chmod is used to change the permissions of files and directories. chmod stands for change mode.
To run the script, you can enter its relative path (./) or absolute path and then filename. We can run the above-created file simply with the below command.
./hello.sh
Note:
Every command in the script works the same way it works in command line.
References