Mon Dec 10 2018

Bash shell and its utility in programming field

Bash shell and its utility in programming field

Today's Bash is more powerful compared to the original Mashey shell and the Bourne shell. Bash stands for Bourne Again SHell, is a "Unix shell". It was created in the late 1980s by a programmer named Brian Fox, working for the Free Software Foundation. It's a command line interface for interacting with the operating system. It is widely available, being the default shell on many GNU/Linux distributions and on Mac OSX, with ports existing for many other systems.  It was intended as a free software alternative to the Bourne shell, and it incorporates all features of that shell, as well as new features such as integer arithmetic and job control.

The ancestor of Bash is the Thompson shell, the first UNIX command interpreter, developed by Ken Thompson in 1971.

Stephen Bourne started working on a new shell early in 1976. The Bourne shell benefited from the concepts introduced by the Mashey shell, and it brought some new ideas of its own. The Bourne shell officially was introduced in UNIX Version 7, released in 1979.

Brian Fox, the Free Software Foundation's first paid programmer, started working on a shell 1988. This became Bash, first released as a beta in 1989. Bash is mostly a clone of the Bourne shell (hence "Bourne-Again"), but it also includes additional features inspired by the C shell and Korn shell. Brian Fox was the official maintainer of Bash until 1992. At the time, Chet Ramey already was involved with the work on Bash, and he became the official maintainer in 1993. And he's still Bash's current maintainer.

The language of Bash commands is a Turing-complete programming language, meaning that if it is even theoretically possible for a given computation to be performed, then it is theoretically possible to perform it in Bash. Furthermore, from a practical standpoint, it is possible to do some very sophisticated things in Bash, and people often do. Nonetheless, it is usually described as a "shell-scripting language" (or similar) rather than a "programming language", and the programs written in it are usually referred to as "Bash shell scripts" (or similar) rather than "Bash programs".

Bash Utilities

  • The main purpose of a UNIX shell is to allow users to interact effectively with the system through the command line. A common shell action is to invoke an executable, which in turn causes the kernel to create a new running process. Shells have mechanisms to send the output of one program as input into another and facilities to interact with the filesystem. For example, a user can traverse the filesystem or direct the output of a program to a file.

  • Bash supports variables, functions and has control flow constructs, such as conditional statements and loops.

  • Bash attempts to fulfill two roles at the same time: to be a command interpreter and a programming language.

  • When a command is entered in Bash, Bash expects that the first word it encounters is a command. However, there's one exception: if the first word contains =, Bash will attempt to execute a variable assignment.

  • Bash allows you to create arbitrary variables on the fly simply by assigning the values to them, it also has a number of built-in variables. An example of a built-in variable is BASHPID. This contains the process ID of the Bash shell itself.

  • Another built-in variable is "?". At any point in a Bash session, this variable contains the return value of the last executed command. The return value is always an integer.

  • Bash provides an impression of a seamlessly integrated command environment, even when the tasks it executes are inherently quite different.

  • Bash filled the special variable "?" with the number 127. This number is hard-wired in Bash, and it specifically means "command not found".

  • In Bash, the "if" statement can take any number of commands separated by a semicolon, after the keyword "if" and before the body denoted with the keyword "then".

  • Brace expansion, also called alternation, is a feature copied from the C shell. It generates a set of alternative combinations. Generated results need not exist as files.

  • When Bash starts, it executes the commands in a variety of dot files. Though similar to Bash shell script commands, which have to execute permission enabled and an interpreter directive like #!/bin/bash, the initialization files used by Bash require neither.

  • Bash supplies "conditional execution" command separators that make execution of a command contingent on the exit code set by a precedent command.

  • Strings in bash are sequences of characters. To create a literal string, use single quotes; to create an interpolated string, use double quotes.

  • In bash, variable scope is at the level of processes: each process has its own copy of all variables.



 

You can share your experiences with us in the comment section. Thank you!

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.