FANDOM


What are this??

Bash

Bash is a command language interpreter which is widely used on various operating systems, and is the default command interpreter on most GNU/Linux systems. The name stands for Bourne-Again SHell.

Shell

Shell is a macro processor which allows for interactive or non-interactive command execution.

Scripting

Scripting allows for commands to be automatically executed that would otherwise be executed manually one-by-one.

Basic knowledge

What is shell

The terminal window contains shell, and shell allows you to use commands that interact with the computer. Tasks like storeing data, processing information, and various other simple or even complex tasks.

Examples of these commands: date, cal, pwd, or ls followed by the enter key.

What is scripting

When running these individual tasks becomes tedious and you want to be able to execute a bunch of commands together, that's when scripting comes in.

For example, we could write a script with the above example commands like so:

task.sh

#!/bin/bash

date
cal
pwd
ls

Once you have written this, we can make the file executable using the chomd -x command. Now your script can be run by typing ./task.sh

With scripting, any shell command can be automated.

We can also automatically execute shell scripts daily at any time by using cron time-based job scheduler and store the script's output to a file every time it is executed.

What is Bash?

Bash is the default interpreter on many GNU/Linux systems, so we could have run task.sh without the initial shebang command. However is it good practice to define the shell interpreter to be used explicitly like we did above.

Because there are various other shell interpreters out there, such as Korn shell and C shell. To see what your default interpreter is simply run:

echo $SHELL

To define your script's interpreter as Bash, first we must locate a full path to its executable binary using the which command. Then prefix with a shebang (#!) and insert it as the first line of your script (like we did in the 'task.sh' example.

Community content is available under CC-BY-SA unless otherwise noted.