Bash ScriptingBash Scripting is a powerful part of system administration and development used at an extreme level. It is used by the System Administrators, Network Engineers, Developers, Scientists, and everyone who use Linux/Unix operating system. They use Bash for system administration, data crunching, web application deployment, automated backups, creating custom scripts for various pages, etc. Script In Computer programming, a script is a set of commands for an appropriate run time environment which is used to automate the execution of tasks. Bash Script:A Bash Shell Script is a plain text file containing a set of various commands that we usually type in the command line. It is used to automate repetitive tasks on Linux filesystem. It might include a set of commands, or a single command, or it might contain the hallmarks of imperative programming like loops, functions, conditional constructs, etc. Effectively, a Bash script is a computer program written in the Bash programming language. How to create and run a Bash Script?
Here, .sh is suffixed as an extension that you have to provide for execution.
Each Bash based Linux script starts by the line- Where #! is referred to as the shebang and rest of the line is the path to the interpreter specifying the location of bash shell in our operating system. Bash use # to comment any line. Bash use echo command to print the output. At the end, execute the bash script prefixing with ./. Have a look at the basic terms of a Bash Script, i.e., SheBang and echo command. SheBang (#!)The She Bang (#!) is a character sequence consisting of the characters number sign (#) and exclamation mark (!) at the beginning of a script. Under the Unix-like operating systems, when a script with a shebang runs as a program, the program loader parses the rest of the lines with the first line as an interpreter directive. So, SheBang denotes an interpreter to execute the script lines, and it is known as the path directive for the execution of different kinds of Scripts like Bash, Python, etc. Here is the correct SheBang format for the discussed Bash Script. The formatting for shebang is most important. Its incorrect format can cause improper working of commands. So, always remember these two points of SheBang formatting while creating a Script as follows:
echoecho is a built-in command in Bash, which is used to display the standard output by passing the arguments. It is the most widely used command for printing the lines of text/String to the screen. Its performance is the same on both the platforms: Bash Shell and Command Line Terminal. Syntax: NOTE: If you want to print space between any two lines of your Script. Then type echo as given below:
Next TopicFilesystem and File Permissions
|