Shell - Startup

Abstract The shell is the primary interface for command execution in Unix-like operating systems. Its behavior upon invocation—whether interactive, non-interactive, login, or non-login—is determined by a cascade of startup files. This paper delineates the types of shell sessions, the corresponding scripts executed (e.g., .bashrc , .profile , .zshrc ), and best practices for configuration management. 1. Introduction When a user opens a terminal or runs a shell script, the shell undergoes an initialization phase. Understanding this phase is critical for system administrators and developers to set environment variables, aliases, functions, and prompt customizations predictably. 2. Shell Session Classification A shell determines its behavior based on two orthogonal attributes:

| Type | Definition | Example | |------|-------------|---------| | | First process after authentication | tty login, ssh , su - user , bash --login | | Non-login shell | Spawned from an existing shell | Terminal emulator tab, bash (no flags), screen | | Interactive shell | Reads/writes to user terminal, prompts for input | Default terminal session | | Non-interactive shell | Runs scripts, no prompt | bash script.sh , sh -c 'echo hi' | shell startup