Javatpoint Logo
Javatpoint Logo

What is Shell Scripting

In Linux, shells like bash and korn support programming construct which are saved as scripts. These scripts become shell commands and hence many Linux commands are script.

A system administrator should have a little knowledge about scripting to understand how their servers and applications are started, upgraded, maintained or removed and to understand how a user environment is built.

A shell script is a type of computer program developed to be executed by a Unix shell, which is also known as a command-line interpreter. Several shell script dialects are treated as scripting languages. Classic operations implemented by shell scripts contain printing text, program execution, and file manipulation. A script configures the environment, executes the program, and does necessary logging or clean-up is known as a wrapper.

Also, the term is more generally used to define the automated mode of executing an operating system shell; all operating systems use a specific name for the functions such as mainframe operating systems, shell scripts (third-party derivatives and Windows NT stream like 4NT), VMS (command procedures), and batch files (OS/2, MSDos-Win95 stream) are related to several terms.

Commonly, shells represent in Unix-like and Unix systems, such as the GNU Bash, the Bourne shell, and the Korn shell. These shells are generally represented for backward compatibility, while the Unix operating system may contain a distinct default shell like MacOS upon zsh.

Capabilities of Shell Script

  • Comments

Comments are avoided by the shell. Typically, they start with the hash (#) symbol and continue until the completion of the line.

  • Scripting language configurable choice

The hash-bang or shebang is a unique type of comment that the system applies to decide what interpreter to utilize to run the file. The hash-bang must be the file's first line and begin with the "#!" symbol. Following the "#!" prefix, the characters are specified as a path to any executable program that will specify the script in Unix-like operating systems.

  • Shortcuts

A shell script can offer an easy variation of the system command in which unique environment settings, post-processing, or command options automatically apply, but in a form that permits the new script to act as a completely normal Unix command.

An example would be to make an ls version, the command for listing files, providing a reduced 'l' command name, which would normally be saved in the bin directory of a user as /home/username/bin/l, and the command option's default set pre-supplied.

In the above example, the first line applies shebang to represent which interpreter should run the rest of the script. The other line creates a listing using options for several file format columns, indicators, all files, and sizes in blocks. The LC_COLLATE=C configures the default collation sequence for not folding lower and uppercase together.

Another shell script example that could be run as a shortcut would be to show all file and directory lists in a given directory.

In the above example, the shell script would begin with its common beginning line of #!/bin/ sh. Following it, the script runs the clear command, which clears the command-line of every text before the next line. The ls -al command will list the directories and files in the directory through which the script is being executed. The attributes of the ls command could be modified to reflect the requirements of the user.

Important: We can use the clr command if an implementation doesn't have a clear command.

  • Batch jobs

A shell script permits many commands that would be manually entered at a command-line interface to be automatically executed without needing to wait for any user to generate all sequence stages.

  • Generalization

Common batch jobs are usual for separated tasks, but using shell variables, tests, and loops gives much more compliance to users. The POSIX sh script is used to transform JPEG images into PNG images, in which the image titles are given possibly by wildcards in the command-line rather than all being listed in the script; it can be made with this file, generally saved inside a file such as /home/username/bin/jpg2png.

  • Programming

Also, several modern shells supply many features generally detected only in more practical general-purpose programming languages like subroutines, arrays, comments, variables, control flow constructs, and so on. With these types of features available, it's possible to reasonably write practical applications as shell scripts.

Although, they are still restricted by the fact that almost all shell languages have no or little support for complex math, data typing systems, threading, classes, and other basic full language aspects, and are also much slower than interpreted languages or compiled code specified with speed as an administration goal.

The standard awk and sed Unix tools give additional capabilities for shell programming. Also, Perl can be installed in shell scripts as other scripting languages such as Tcl. Tcl and Perl also provide graphics toolkits.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA