C.W.K.
Stream
Lesson 02 of 10 · published

Shell 의 짧은 역사 — sh → bash → zsh → fish

~15 min · history, sh, bash, zsh, fish, posix

Level 0창 구경꾼
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

왜 shell 의 역사를 알아야 해?

1989 년에 쓰인 sh 스크립트랑 지난 주에 쓴 zsh 설정 파일을 동시에 읽게 돼. 각 도구가 어떤 shell 을 노렸는지 알아두면 bash 전용 문법을 POSIX 스크립트에 그대로 복붙해서 CI 에서 터지는 사고를 막아.

1979 — Bourne shell (sh)

Stephen Bourne 이 Bell Labs 에서 sh 를 썼어. 이후 모든 shell 이 베낀 문법 — pipe, if/then/fi, here-doc, 환경 변수, $? — 이 다 여기서 시작했어. 지금도 #!/bin/sh 로 선언하면 array 도 없고, [[ ]] 도 안 되는 minimal POSIX 문법으로 돌아가.

1989 — Bourne Again (bash)

bash 는 GNU 가 만든 Bourne 대체품이야. Korn shell, C shell 에서 좋은 거 다 흡수했어 — history, line editing, array, [[ ]], $(...) 등. macOS 는 10.3 (2003) ~ 10.15 (2019) 까지 bash 를 기본 shell 로 썼는데 GPLv3 라이센스 변경 때문에 Apple 이 3.2 버전에서 동결했어.

1990 — Z shell (zsh)

Paul Falstad 가 zsh 를 'bash 에 다른 shell 의 좋은 점 다 더한 것' 으로 설계했어. 더 똑똑한 completion, 재귀 globbing (**), 프롬프트 테마, 디렉터리 네이밍, Oh-My-Zsh / Prezto / zinit 같은 모듈 플러그인. macOS Catalina (2019) 가 zsh 를 default login shell 로 삼았어.

2005 — fish

fish ('friendly interactive shell') 는 POSIX 호환성을 의도적으로 버렸어. 어떤 shell 보다 default 가 똑똑해 — autosuggestion, syntax highlighting, 깔끔한 scripting 문법. 대신 bash 스크립트가 그대로 안 돌아가. fish 는 프롬프트용이고, 휴대 가능한 스크립트용이 아니야.

현실 규칙

인터랙티브 프롬프트는 zsh (또는 fish) 로. 다른 머신에 배포할 스크립트는 bash 나 POSIX sh 로. 스크립트 인터프리터를 절대 추측하지 말고 항상 shebang 으로 못 박기.

Code

이 Mac 에 깔린 shell 들·bash
# All registered login shells
cat /etc/shells
# Where each one lives
for s in sh bash zsh fish; do
  printf '%-5s -> ' "$s"
  command -v "$s" || echo '(not installed)'
done
shebang 으로 인터프리터 못 박기·bash
#!/usr/bin/env bash
# Use bash specifically, not whatever sh happens to be linked to
set -euo pipefail
echo "running on $(bash --version | head -1)"

External links

Exercise

Mac 에서 cat /etc/shells 실행. 이어서 command -v bashbash --version. bash 가 3.2.x 인 거 확인. 모던 bash 가 필요하면 brew install bash 깔고 다시 command -v bash — Homebrew 는 /opt/homebrew/bin/bash, 시스템은 /bin/bash 인 거 직접 보기.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.