Interactive Shell
An interactive shell is a command-line interface (CLI) that allows you to interact with the operating system by typing commands and receiving immediate feedback. When you open a terminal and start entering commands, you’re using an interactive shell. The key characteristics of an interactive shell are:
- Real-time interaction: You can type a command, press Enter, and see the output immediately.
- User prompts: The shell provides prompts (like
$
or#
in Unix-like systems) to indicate that it’s ready to receive input. - Input and Output: Commands are entered manually by the user, and output is displayed on the terminal screen.
Examples of interactive shells include bash
, zsh
, and fish
.
Non-Interactive Shell
A non-interactive shell is a shell that runs scripts or commands without requiring user interaction. It’s typically used for executing batch processes, scripts, or commands in the background. In this mode, the shell reads commands from a file or other input source rather than from the user directly.
- No real-time interaction: Commands are executed automatically without waiting for user input.
- No prompts: Since there is no interaction, the shell doesn’t display a prompt.
- Used in automation: Commonly used in scripts, cron jobs, or other automated processes.
An example of a non-interactive shell is when you run a script like bash script.sh
, where the script is executed without requiring further input.
Interactive Mode
Interactive mode refers to a mode in a program where the user can interact with it directly, usually by typing commands and receiving immediate feedback. This mode is not limited to shells but can be found in many programming languages and tools.
Python Example: When you type
python
in the terminal and get the>>>
prompt, you’re in Python’s interactive mode. Here, you can type Python commands and see the results instantly.Debuggers: Many debuggers also have interactive modes where you can inspect and modify variables, step through code, and interact with the program in real time.
Login Shell vs Non-Login Shell
Login Shell
: This is the shell session that is started when you log into your system (either physically or remotely, like through SSH). A login shell typically reads configuration files such as.bash_profile
,.bash_login
, or.profile
for environment setup.Non-Login Shell
: This shell is typically started by a terminal emulator after you have logged in. It usually reads configuration files like.bashrc
. Non-login shells are common when you open a new terminal window on a desktop.