Cheat Sheet - Linux: /kr/linux/ - CLI: /kr/linux/cli/ - locate vs type vs which vs whereis: /kr/linux/cli/locate-vs-type-vs-which-vs-whereis/ - make: /kr/linux/cli/make/ - awk: /kr/linux/cli/awk/ - find: /kr/linux/cli/find/ - grep: /kr/linux/cli/grep/ - pgrep: /kr/linux/cli/pgrep/ - ps: /kr/linux/cli/ps/ - pstree: /kr/linux/cli/pstree/ - trap: /kr/linux/cli/trap/ - xargs: /kr/linux/cli/xargs/ - Shell: /kr/linux/shell/ - BASH_SOURCE: /kr/linux/shell/bash-source/ - Redirection: /kr/linux/shell/redirection/ - Special Variables: /kr/linux/shell/special-variables/ - Interactive Shell과 Login Shell의 정의: /kr/linux/shell/interactive-login/ - Scripting Tips: /kr/linux/shell/script-tips/ - set -o vi: /kr/linux/shell/bash-vi-mode/ - Shell 실행 순서: /kr/linux/shell/process-order/ - Double Quote Expansion: /kr/linux/shell/shell-expansion/ - System Programming: /kr/linux/system-programming/ - File I/O: /kr/linux/system-programming/file-io/ - Process: /kr/linux/system-programming/process/ - Shared Libraries: /kr/linux/system-programming/shared-libraries/ - Kernel: /kr/linux/kernel/ - Go: /kr/programming/go/ - Concurrency: /kr/programming/go/concurrency/ - CSP (Communicating Sequential Processes) and Channels: /kr/programming/go/concurrency/csp/ - Channel: /kr/programming/go/concurrency/channel/ - Select: /kr/programming/go/concurrency/select/ - sync: /kr/programming/go/concurrency/sync/ - Concurrency Patterns: /kr/programming/go/concurrency/patterns/ - Goroutines and the Go Runtime: /kr/programming/go/concurrency/runtime/ - 표준 라이브러리: /kr/programming/go/std/ - os: /kr/programming/go/std/os/ - context: /kr/programming/go/std/context/ - io: /kr/programming/go/std/io/ - json: /kr/programming/go/std/json/ - net/http: /kr/programming/go/std/net-http/ - slog: /kr/programming/go/std/slog/ - testing: /kr/programming/go/std/testing/ - time: /kr/programming/go/std/time/ - Ellipsis (...): /kr/programming/go/ellipsis/ - error: /kr/programming/go/error/ - Function: /kr/programming/go/function/ - Go Tool: /kr/programming/go/tool/ - Interface: /kr/programming/go/interface/ - Map: /kr/programming/go/map/ - Package and Module: /kr/programming/go/package-module/ - Pointer: /kr/programming/go/pointer/ - Slice: /kr/programming/go/slice/ - String: /kr/programming/go/string/ - Switch: /kr/programming/go/switch/ - Comparison: /kr/programming/go/comparison/ - defaultdict: /kr/programming/python/collections/defaultdict/ - heapq: /kr/programming/python/collections/heapq/ - @cache: /kr/programming/python/cache/ - abc: /kr/programming/python/abc/ - bisect: /kr/programming/python/bisect/ - Type Hints: /kr/programming/python/type-hints/ - Passing Mechanism: /kr/programming/python/passing-mechanism/ - uv: /kr/programming/python/uv/ - *args and **kwargs: /kr/programming/python/args-kwargs/ - re: /kr/programming/python/re/ - C: /kr/programming/c/ - 포인터와 배열: /kr/programming/c/pointer/ - Syntax Basics: /kr/programming/c/syntax-basics/ - static: /kr/programming/c/static/ - Bit Manipulation: /kr/programming/c/bit-manipulation/ - C vs C++: /kr/programming/c/c-vs-cpp/ - stdatomic: /kr/programming/c/stdatomic/ - C++: /kr/programming/cpp/ - RAII (Resource Acquisition Is Initialization): /kr/programming/cpp/raii/ - Copy Elision & Move Semantics: /kr/programming/cpp/copy-elision-and-move-semantics/ - Most Vexing Parse & In-Class Initializer: /kr/programming/cpp/most-vexing-parse/ - C++ Keywords Reference: /kr/programming/cpp/keywords/ - C++ Primer: /kr/programming/cpp/primer/ - Variables and Basic Types: /kr/programming/cpp/primer/variables-and-basic-types/ - Expressions: /kr/programming/cpp/primer/expressions/ - Type Conversions and Casts: /kr/programming/cpp/primer/type-conversions-and-casts/ - Statements: /kr/programming/cpp/primer/statements/ - Functions: /kr/programming/cpp/primer/functions/ - Classes: /kr/programming/cpp/primer/classes/ - The IO Library: /kr/programming/cpp/primer/io-library/ - STL: /kr/programming/cpp/primer/stl/ - Lambda Expressions: /kr/programming/cpp/primer/lambda/ - Smart Pointers: /kr/programming/cpp/primer/smart-pointers/ - Copy Control: /kr/programming/cpp/primer/copy-control/ - Overloaded Operations and Conversions: /kr/programming/cpp/primer/operator-overloading/ - Object-Oriented Programming (OOP): /kr/programming/cpp/primer/oop/ - Templates and Generic Programming: /kr/programming/cpp/primer/templates/ - Namespaces: /kr/programming/cpp/primer/namespaces/ - Pointers to Class Member: /kr/programming/cpp/primer/pointers-to-class-member/ - Advanced: /kr/programming/cpp/advanced/ - Error Handling: /kr/programming/cpp/advanced/error-handling/ - Concurrency & Threading: /kr/programming/cpp/advanced/concurrency/ - Unit Testing: /kr/programming/cpp/advanced/unit-testing/ - 언어 별 비교: /kr/programming/comparison/ - Kubernetes: /kr/cloud-devops/kubernetes/ - Fleet: /kr/cloud-devops/kubernetes/gke/fleet/ - Kustomize vs Helm: /kr/cloud-devops/kubernetes/kustomize-vs-helm/ - API Extension: /kr/cloud-devops/kubernetes/api-extension/ - Concept: /kr/cloud-devops/kubernetes/kueue/concept/ - DRA: /kr/cloud-devops/kubernetes/dra/ - Secret Manager: /kr/cloud-devops/terraform/google-secret-manager/ - Knowledge: /kr/network/knowledge/ - PDU: /kr/network/knowledge/osi-model/ - curl: /kr/network/cli/curl/ - Concurrency Concepts: /kr/cs/concurrency-and-parallelism/concepts/ - Concurrency vs Parallelism: /kr/cs/concurrency-and-parallelism/concurrency-vs-parallelism/ - Mutex vs Atomic: /kr/cs/concurrency-and-parallelism/mutex-vs-atomic/ - Regular Expression: /kr/cs/regular-expression/ - Multiplexer vs Dispatcher: /kr/cs/multiplexer-vs-dispatcher/ - Driver and Runtime: /kr/ai-ml/gpu/driver-and-runtime/ - Serving: /kr/ai-ml/serving/ - Dotfiles: /kr/dotfiles/ - Git: /kr/dotfiles/git/ - Cheat Sheet: /kr/dotfiles/git/cheat-sheet/ - revisions: /kr/dotfiles/git/revisions/ - Submodule vs Worktree: /kr/dotfiles/git/submodule-vs-worktree/ - checkout, reset -> switch, restore: /kr/dotfiles/git/checkout-switch-restore-reset/ - rebase: /kr/dotfiles/git/rebase/ - Branching and Merging: /kr/dotfiles/git/branching-merging/ - Vim: /kr/dotfiles/vim/ - Plugin: /kr/dotfiles/vim/plugin/ - auto-pairs: /kr/dotfiles/vim/plugin/auto-pairs/ - vim-commentary: /kr/dotfiles/vim/plugin/vim-commentary/ - vim-easymotion: /kr/dotfiles/vim/plugin/vim-easymotion/ - vim-surround: /kr/dotfiles/vim/plugin/vim-surround/ - Marks: /kr/dotfiles/vim/tips/marks/ - vimrc: /kr/dotfiles/vim/vimrc/ - lf: /kr/dotfiles/lf/ # Interactive Shell과 Login Shell의 정의 셸의 종류는 **Interactive** 여부와 **Login** 여부라는 두 가지 독립적인 기준으로 구분된다. ## 1. 기술적 정의 ### 1.1 Interactive Shell 셸은 다음 조건 중 하나를 만족할 때 기술적으로 **Interactive Shell**(대화형 셸)로 간주된다. - 옵션이 아닌 인자(단, `-s` 제외)와 `-c` 옵션 없이 실행되었으며, **표준 입력**(stdin)과 **표준 에러**(stderr)가 모두 터미널에 연결된 경우(`isatty(3)`로 판단). [^1] - `-i` 플래그와 함께 명시적으로 실행된 경우. **확인 방법:** - `[[ $- == *i* ]] && echo "Interactive" || echo "Non-interactive"` - `[[ -n "$PS1" ]] && echo "Interactive" || echo "Non-interactive"` ### 1.2 Login Shell 셸은 오직 다음 조건 중 하나를 만족할 때만 기술적으로 **Login Shell**로 간주된다. - 첫 번째 인자(`argv[0]`)의 시작 문자가 하이픈인 경우 (eg. `-bash`). [^2] - `--login` (또는 `-l`) 플래그와 함께 명시적으로 실행된 경우. **확인 방법:** - `shopt login_shell` (로그인 셸인 경우 `on` 반환) `ssh host `가 로그인 셸이 아닌 이유는 SSH가 셸을 실행할 때 `bash -c ""` 형식을 사용하기 때문이다. 이 방식은 하이픈이나 로그인 플래그를 포함하지 않는다. ## 2. 셸의 조합 Interactive 셸과 Login 셸 사이에는 엄격한 포함 관계가 없다. | | Login | Non-Login | | :--- | :--- | :--- | | **Interactive** | **Interactive Login Shell**
eg. SSH 로그인, 로컬 콘솔 로그인 | **Interactive Non-Login Shell**
eg. 터미널에서 `bash` 실행 | | **Non-Interactive** | **Non-Interactive Login Shell**
eg. `su - -c `[^4], `bash --login -c ` | **Non-Interactive Non-Login Shell**
eg. `bash -c `, `su -c `, `ssh host `[^3], `./script.sh`, Crontab | ## 3. 설정 파일 셸의 종류에 따라 실행되는 설정 파일이 다르다. [^5] - **Login Shell** (Interactive 또는 Non-Interactive): 1. `/etc/profile` 2. `~/.bash_profile`, `~/.bash_login`, `~/.profile` 중 **가장 먼저 발견되는 파일 하나**만 실행. {{% hint warning %}} **Login Shell은 `~/.bashrc`를 자동으로 실행하지 않는다.** 로그인 셸에서 `~/.bashrc`가 실행되는 이유는 보통 `~/.profile`이나 `~/.bash_profile` 내부에 이를 직접 불러오는(source) 코드가 포함되어 있기 때문이다. ```bash # if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi ``` {{% /hint %}} - **Non-Login Shell** - **Interactive Non-Login Shell**: `~/.bashrc` - **Non-Interactive Non-Login Shell**: 보통 없음 (설정된 경우 `$BASH_ENV` 읽음). ### 3.1 `$PATH` 설정과 `.profile` `$PATH` 변수는 `~/.bashrc`가 아닌 `~/.profile`에서 설정하는 것이 권장된다. - **상속 (Inheritance)**: 로그인 셸에서 (`~/.profile`을 통해) 설정된 환경 변수는 모든 하위 프로세스(서브셸 포함)에 상속된다. 즉, 로그인 시 (`~/.profile`) 한 번 설정하는 것만으로 모든 서브셸에 적용된다. - **효율성 (Efficiency)**: `$PATH`를 `~/.bashrc`에 설정하면 서브셸이 실행될 때마다 중복해서 처리되므로 비효율적이며, `$PATH`가 불필요하게 중복되거나 길어질 수 있다. ## References [^1]: **bash(1)**: "An interactive shell is one started without non-option arguments (unless -s is specified) and without the -c option, and whose standard input and standard error are both connected to terminals (as determined by isatty(3)), or one started with the -i option." [^2]: **bash(1)**: "A login shell is one whose first character of argument zero is a -, or one started with the --login option." [^3]: **bash(1)**: "Bash attempts to determine when it is being run by the remote shell daemon, usually rshd, or the secure shell daemon sshd. If bash determines it is being run non-interactively in this fashion, it reads and executes commands from ... ~/.bashrc." When `bash` is run non-interactively by `sshd`, it is **not** a login shell, but it specifically reads `~/.bashrc` anyway. [^4]: **su(1)**: "Start the shell as a login shell with an environment similar to a real login." The hyphen (`-`) is a shortcut for `--login`. The `-c` flag makes the shell non-interactive as it executes a command instead of reading from a terminal. [^5]: **bash(1)**: "When bash is invoked as an interactive login shell... it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable."