A Unix/Linux shell is a command-line interpreter. Users commonly interacts with shell, using terminal emulator by entering command as text or from a file that can be interpreted by shell. The shell can be an interactive command-line as well as scripting programming language.

starting-with-bash-shell-scripting-language

Features of Linux/Unix Shell

  1. Wildcarding
  2. Piping
  3. Command substituion
  4. Variables
  5. Control Structure
  6. Condition Testing
  7. Iteration

Some well known Linux shell

  1. Bourne Shell – The most basic shell that is available on all UNIX System.
  2. Korn Shell – Based on Bourne Shell with advanced features.
  3. C Shell – Syntaxally close to C programming Language, the name says it all.
  4. Bash Shell – The default shell on most Linux Distribution. It has the avantages of Korn and C shell.
  5. tcsh – Very similar to C shell.

A short note on Bash Shell

Bash Shell was written by Brian Fox, the first employee of Free Software Foundation. Fox started coding bash on January 10, 1988 and the initial release was made 18 months after, on June 08, 1989. It was written in C programming language and released under GNU GPL v3+ License. The latest stable release is Version 4.4.

Features of Bash Shell

  1. Bash command syntax is a superset of Bournie Shell command Syntax. Most of the script of Bournie shell can be run on Bash as it is without modification.
  2. Command-line editing
  3. Command history
  4. Directory Stack
  5. POSIX Command substitution syntax
  6. $RANDOM and $PPID Variables
  7. Tab auto-completion
  8. Arithmetic evaluation
  9. I/O redirection
  10. Process substituion
  11. Named pipes
  12. Bash 4.0 has built-in fake support for multi-dimensional arrays, like awk.
  13. Portability
  14. Process Management
  15. Conditional execution

Bash shebang

You must have noticed something like below on the first-line of shell script.

The bash script must start with a Bash shebang. It tells the shell what environment to use.
For portability it is recommended to use it as

#!/usr/bin/env bash

Comments in Bash

Bash has support for single-line comment as well as multi-line comment. Bash interprets anything after ‘#’ as comment.

Single-line comment example

Multi-line comment example

Hello World Program in Shell

You can save it to anything. However, following the convention we will save it as hello-world.sh. Next it is important to give the script executable permission. It can be done by running the below command in terminal

$ chmod 755 hello-world.sh

All you need to do, to execute the script is

A Unix/Linux shell is a command-line interpreter. Users commanly interacts with shell, using terminal emulator by entering command as text or from a file that can be interpreted by shell. The shell can be an interactive command-line as well as scripting programming language.

Features of Linu/Unix Shell

  • Wildcarding
  • Piping
  • Command substituion
  • Variables
  • Control Structure
  • Condition Testing
  • Iteration

Some well known Linux shell

  • Bourne Shell – The most basic shell that is available on all UNIX System.
  • Korn Shell – Based on Bourne Shell with advanced features.
  • C Shell – Syntaxally close to C programming Language, the name says it all.
  • Bash Shell – The default shell on most Linux Distribution. It has the avantages of Korn and C shell.
  • tcsh – Very similar to C shell.

A short note on Bash Shell

Bash Shell was written by Brian Fox, the first employee of Free Software Foundation. Fox started coding bash on January 10, 1988 and the initial release was made 18 months after, on June 08, 1989. It was written in C programming language and released under GNU GPL v3+ License. The latest stable release is Version 4.4.

Features of Bash Shell

  • Bash command syntax is a superset of Bournie Shell command Syntax. Most of the script of Bournie shell can be run on Bash as it is without modification.
  • Command-line editing
  • Command history
  • Directory Stack
  • POSIX Command substitution syntax
  • $RANDOM and $PPID Variables
  • Tab auto-completion
  • Arithmetic evaluation
  • I/O redirection
  • Process substituion
  • Named pipes
  • Bash 4.0 has built-in fake support for multi-dimensional arrays, like awk.
  • Portability
  • Process Management
  • Conditional execution

Bash shebang

You must have noticed something like below on the first-line of shell script.

The bash script must start with a Bash shebang. It tells the shell what environment to use.
For portability it is recommended to use it as

#!/usr/bin/env bash

Comments in Bash

Bash has support for single-line comment as well as multi-line comment. Bash interprets anything after ‘#’ as comment.

Single-line comment example

Multi-line comment example

Hello World Program in Shell

writing - Hello world Shell Script

You can save it to anything. However, following the convention we will save it as hello-world.sh. Next it is important to give the script executable permission. It can be done by running the below command in terminal

$ chmod 755 hello-world.sh

All you need to do, to execute the script is

executing - Hello world Program

Whoa! You just run your first shell script. It was simple, isn’t it?

That’s all for now. You can write a shell script to print some other line of text, in order to learn how it works. In the next article we will go through numerical and mathematical calculations. Do comment and write your feedback below. Stay connected to JoinTux.

Whoa! You just run your first shell script. It was simple, isn’t it?

That’s all for now. You can write a shell script to print some other line of text, in order to learn how it works. In the next article we will go through numerical and mathematical calculations. Do comment and write your feedback below. Stay connected to JoinTux.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here