Bash
Bash
command line. It's also referred to as a shell because it envelops the operating system kernel,
obscuring its complex details while enabling you, the programmer, to perform essential tasks like
accessing data and writing files using simple commands. This concept was revolutionary when
introduced in the early 1970s, a time when programmers were still working with punch cards. Over
the years, the shell concept evolved, with the Bourne shell becoming the most popular version until
1989 when the Bourne Again Shell, or Bash, was developed.
When you open the terminal on a Unix-based system like macOS or most Linux distributions, the
default shell is usually Bash. It provides a prompt where you can type commands, which the shell
interprets and executes on the operating system. To check if you're running Bash, you can type `which
$SHELL` in the command line. Bash resides in the binaries directory like any other application but also
serves as a programming language that allows for scripting. Anything you can manually type into the
command line can be automated with Bash scripts.
When you start the shell, it runs a startup script defined in the `.bash_profile` or `.bashrc` file on your
system, enabling you to customize the shell's behavior and appearance for each new session. You can
create custom Bash scripts for any project by making a file that ends in `.sh` or has no extension at all.
The first line of this file should always be a shebang , indicating the path to the application that should
run the script. Below this, you can write commands, which will be interpreted line by line.
To create a variable, type a name in all caps, followed by an equal sign, and later reference it in the
script using a dollar sign before the name. To run the script, simply type the file name into the shell.
If you want to pass arguments when running the script, positional arguments are automatically
assigned variable names like `$1`, `$2`, `$3`, and so on. For additional user input in the middle of a
script, you can create loops, such as a do-while loop, to prompt the user to continue the script or exit
based on their input. Conditional logic can be implemented with an if statement to test if a value on
the left is less than a value on the right, executing different commands based on the result.
Additionally, you can run multiple long-running processes in parallel by adding an ampersand (`&`)
after each command. This overview covers Bash, the Bourne Again Shell. If you want more short
videos like this, make sure to hit the like button and subscribe. Thanks for watching, and see you next
time.