Table of Contents
Compiled vs. Interpreted
shis a compiled binary, often written in C..shis a shell script — a plain text file interpreted by a shell likesh,bash, orzsh.- Compiled executables can run directly. Scripts require an interpreter.
Shebang
- A shebang (
#!) tells the shell which program to use to run the script. - Syntax:
#! interpreter [optional-arg]
Examples:
#!/bin/bash # Bash
#!/usr/bin/zsh # Zsh
#!/usr/bin/python3 # Python 3
- Without a shebang, scripts need to be run like:
bash script.sh
Config Files
-
Used to configure the shell at startup:
- Bash:
~/.bashrc - Zsh:
~/.zshrc
- Bash:
These files can set:
- Environment variables
- Aliases
- PATH modifications
Environment Variables
- Available to all child processes of the shell.
- View current variables:
env
- Set a variable:
export NAME="Adarsh"
echo $NAME
- Scripts can access exported variables:
introduce.sh:
#!/bin/sh
echo "Hi I'm $NAME"
Make it executable:
chmod +x introduce.sh
./introduce.sh # Hi I'm Adarsh
PATH Variable
- A colon-separated list of directories the shell checks to find commands.
echo $PATH
Example:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
- Without PATH, you’d have to run
/bin/lsinstead of justls.
Modifying PATH
- Append a new directory to your current PATH:
export PATH="$PATH:/your/custom/path"
- Add this to
~/.bashrcor~/.zshrcto make it persistent across sessions.