OTHER·중요도 5·2026. 07. 26.·GeekNews

셸의 콜론은 아무것도 하지 않는다. 그래도 사용하라

── KO ──────────────────

셸의 콜론(:)으로 인수 평가와 기본값 설정을 간결하게 할 수 있다.

셸의 콜론(:)은 어떤 동작도 수행하지 않는 널 명령으로, 매개변수 확장과 결합하여 필수 인수 검사와 기본값 설정이 가능하다. 예를 들어, <code>: &quot;${1:?missing argument, aborting!}&quot;</code>와 같은 방식으로 인수가 없을 때 오류를 발생시킬 수 있다. 이 방법을 통해 스크립트를 보다 간결하고 효율적으로 작성할 수 있다.


── EN ──────────────────

The shell colon (:) serves as a null command for argument evaluation and default value assignments.

The shell colon (:) acts as a null command that performs no action but can evaluate arguments. When combined with parameter expansion, it simplifies essential argument checks and default value assignments. For example, using <code>: &quot;${1:?missing argument, aborting!}&quot;</code> triggers an error if an argument is missing, making scripts cleaner and more efficient.

원문 보기 →목록으로