SHELL
A Unix shell script is a program written for the shell or
command-line interpreter of the Unix operating system
Types of Unix Shells:
Bash (Bourne Again Shell) - Most commonly used
Sh (Bourne Shell) - The original shell
C Shell (csh) - C-like syntax
Korn Shell (ksh) - Advanced scripting capabilities
Z Shell (zsh) - Highly customizable
Basic Shell Scripting Syntax:
1. Shebang Line (Interpreter Directive)
Every shell script start with a shebang (#!) to specify the shell
interpreter.
#!/bin/bash # For Bash shell
#!/bin/sh # For default shell
Tells the system which interpreter to use.
#!/bin/ksh -- Korn Shell (ksh)
#!/bin/csh -- C Shell (csh)
#!/bin/zsh -- Z Shell (zsh)
2. Variables
In UNIX, there are two types of variables
System Variables
- Predefined by the system and usually in uppercase
- Examples: $HOME, $PATH, $USER, $SHELL, $PWD
User-Defined Variables
- Created and customized by the user
- Example:
my_var=”Hello, Unix”
echo $my_var
- Assign values without space around = (equal sign)
3. Variables
Use # to add comments (ignored by the shell).
# This is a comment
echo “Hello, World” #it prints the text