DEV Community

Aryan Vaishnani
Aryan Vaishnani

Posted on

Shell Basics (Bash, Zsh, Sh)

A shell is a command-line interpreter that allows users to interact with the Linux operating system.

The shell:

  1. Accepts commands
  2. Executes programs
  3. Manages scripts
  4. Handles automation
  5. Controls system operations

What is a Shell?

When you type a command like:

ls

The shell:

  1. Reads the command
  2. Finds the executable
  3. Executes it
  4. Displays output

Common Linux Shells:

Shell Full Name Main Usage
sh Bourne Shell Original Unix shell
bash Bourne Again Shell Most common Linux shell
zsh Z Shell Advanced interactive shell

1. Sh (Bourne Shell)

About

  • One of the oldest Unix shells
  • Created for early Unix systems
  • Lightweight and simple

Features

  1. Basic scripting
  2. POSIX compatible
  3. Minimal functionality

Location

/bin/sh

Usage

sh script.sh

2. Bash (Bourne Again Shell)

About

Most widely used Linux shell.

Default shell in many Linux distributions.

Bash

Features of Bash

  1. Command history
  2. Tab completion
  3. Variables
  4. Scripting support
  5. Aliases
  6. Job control
  7. Pipes and redirection

Check Current Shell

echo $SHELL

Bash Configuration Files

File Purpose
~/.bashrc Interactive shell config
~/.bash_profile Login shell config
/etc/bashrc Global bash config

3. Zsh (Z Shell)

About

Advanced shell with better user experience and customization.

Features of Zsh

  1. Better auto-completion
  2. Smart suggestions
  3. Advanced themes
  4. Plugin support
  5. Better productivity

Install Zsh

Ubuntu/Debian

sudo apt install zsh -y

Change Default Shell to Zsh

chsh -s $(which zsh)

Logout and login again.

Zsh Configuration File

~/.zshrc

Install Oh My Zsh

Popular Zsh framework.

Oh My Zsh Official Website

Install:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Real-World Zsh Plugins

Git Plugin

Edit:

nano ~/.zshrc

Add:

plugins=(git docker kubectl)

Reload:

source ~/.zshrc

Real-World Practical Example

DevOps Engineer Shell Setup

A DevOps engineer managing:

  1. Docker
  2. Kubernetes
  3. Git
  4. Cloud servers

Usually configures shell for faster operations.

Practical Bash Example

Create Productivity Aliases

Edit:

nano ~/.bashrc

Add:

alias k='kubectl'
alias d='docker'
alias dc='docker compose'
alias gs='git status'
alias gp='git pull'
alias tf='terraform'

Reload:

source ~/.bashrc

Now commands become:

k get pods
d ps
gs
tf apply

This is heavily used in:

  1. DevOps
  2. Cloud engineering
  3. Kubernetes administration
  4. Linux server management

Useful Shell Commands

View Current Shell

echo $0

List Available Shells

cat /etc/shells

Switch Shell Temporarily

bash
zsh
sh

Shell Scripting Example

Simple Script

Create:

nano backup.sh

Add:

#!/bin/bash
echo "Backup Started"
tar -czf backup.tar.gz /home/user/data
echo "Backup Completed"

Run:

chmod +x backup.sh

./backup.sh

Real-World Usage

Area Common Shell
Linux servers Bash
DevOps Bash + Zsh
Automation Bash
CI/CD pipelines Sh/Bash
Kubernetes management Zsh/Bash
Cloud administration Bash

Top comments (0)