목차

, , , ,

printf

printf는 format string에 따라 문자열과 숫자를 변환해 표준 출력으로 내보내는 명령이다. 많은 shell이 builtin으로 제공하며, GNU/Linux에서는 GNU coreutils의 외부 명령도 함께 사용할 수 있다.

Summary

Installation

대부분의 Unix 계열 shell에는 printf builtin이 이미 포함되어 있다. 아래 명령은 외부 GNU printf가 필요할 때 GNU coreutils package를 설치하는 방법이다.

Debian / Ubuntu

sudo apt update
sudo apt install coreutils

RHEL / Fedora

sudo dnf install coreutils

macOS

macOS에는 system printf가 기본 제공된다. GNU coreutils 구현이 필요하면 Homebrew formula를 설치한다. macOS 기본 명령과 이름이 겹치므로 Homebrew 구현은 일반적으로 gprintf로 설치된다.

brew install coreutils
gprintf --version

Windows

GNU coreutils project가 공식 배포하는 native Windows winget package는 확인되지 않는다. WSL 또는 사용하는 Unix-compatible shell 환경에서 제공하는 printf를 사용하고 해당 환경의 문서를 확인한다.

Verification

command -V printf
env printf --version

Usage

printf FORMAT [ARGUMENT]...
printf OPTION

Format

Conversion directives

and all C format specifications ending with one of diouxXfeEgGcs, with ARGUMENTs converted to proper type first. Variable widths are handled.

NOTE: your shell may have its own version of printf, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/> Report printf translation bugs to <https://translationproject.org/team/> Full documentation at: <https://www.gnu.org/software/coreutils/printf> or available locally via: info '(coreutils) printf invocation' </code> ++++

See Also

History