echo 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-echo
핵심 정리
- 문자열을 빈칸으로 나눠 표준 출력에 쓰고, 끝에 줄바꿈을 붙입니다. 인수가 없으면 빈 줄을 씁니다.
- AIX의
echo는 플래그를 받지 않습니다.-n이나--도 글자 그대로 출력합니다. - 대신 이스케이프를 늘 해석합니다:
\n,\t,\c(끝 줄바꿈 생략),\0숫자(8진수 문자) 등. - 백슬래시는 셸이 먼저 한 번 줄이고
echo가 다시 해석하므로, 이스케이프가 든 문자열은 따옴표로 감쌉니다. bsh와ksh의 내장echo는 이 명령과 같고,csh의 내장echo는 다르게 동작합니다.- AIX 5.3과 6.1 문서의 내용이 같습니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (두 버전 내용 같음) |
| 원문 | IBM Commands Reference — 5.3 Volume 2, 6.1 Volume 2 |
| 파일 | /usr/bin/echo |
| 관련 명령어 | printf, ksh, bsh, csh |
목적
문자열을 표준 출력에 씁니다.
영어 원문
Writes character strings to standard output.
구문
echo [ String ... ]
설명
echo 명령은 문자열을 표준 출력에 씁니다. 문자열은 빈칸으로 나뉘고, 마지막 String 매개변수 뒤에 줄바꿈 문자가 붙습니다. String 매개변수가 없으면 빈 줄(줄바꿈 문자)을 표시합니다.
보통은 --(하이픈 두 개)로 플래그와 하이픈으로 시작하는 문자열을 구분할 수 있습니다. 하지만 echo 명령은 플래그를 지원하지 않으므로 --도 글자 그대로 다룹니다.
echo 명령은 다음 이스케이프 규칙을 인식합니다.
| 이스케이프 | 표시하는 것 |
|---|---|
\a |
경고 문자 |
\b |
백스페이스 |
\c |
마지막 인수 뒤에 붙는 줄바꿈을 생략합니다. \c 뒤의 문자는 모두 무시합니다. |
\f |
폼 피드 |
\n |
줄바꿈 |
\r |
캐리지 리턴 |
\t |
탭 |
\v |
세로 탭 |
\\ |
백슬래시 |
\0Number |
ASCII 값이 0~3자리 8진수 Number인 8비트 문자 |
참고: bsh, ksh, csh 명령에는 각각 echo 내장 하위 명령이 있습니다. echo 명령과 bsh·ksh의 echo는 같게 동작하지만, csh의 echo는 다르게 동작합니다.
\(백슬래시)는 셸의 인용 문자입니다. 그래서 이스케이프 문자와 함께 쓰거나 "\", '\'처럼 따옴표로 감싸지 않으면, 셸이 명령을 펼칠 때 백슬래시를 없앱니다.
셸이 펼친 뒤 echo가 입력의 이스케이프 시퀀스에 따라 출력합니다. 다음 표는 명령의 백슬래시가 셸에서 한 번, echo에서 한 번 줄어드는 모습을 비교합니다.
| 입력한 명령 | 셸이 펼친 뒤 | echo가 처리한 뒤 |
|---|---|---|
echo hi\\\\there |
echo hi\\there |
hi\there |
echo 'hi\\\\there' |
echo 'hi\\\\there' |
hi\\there |
echo "hi\\\\there" |
echo "hi\\there" |
hi\there |
영어 원문
The echo command writes character strings to standard output. Strings are separated by spaces, and a new-line character follows the last String parameter specified. If no String parameter is specified, a blank line (new-line character) is displayed.
Normally you could distinguish between a flag and a string that begins with a hyphen by using a — (double hyphen). Since no flags are supported with the echo command, a — (double hyphen) is treated literally.
The echo command recognizes the following escape conventions:
\a— Displays an alert character.\b— Displays a backspace character.\c— Suppresses the new-line character that otherwise follows the final argument in the output. All characters following the\csequence are ignored.\f— Displays a form-feed character.\n— Displays a new-line character.\r— Displays a carriage return character.\t— Displays a tab character.\v— Displays a vertical tab character.\\— Displays a backslash character.\0Number— Displays an 8-bit character whose ASCII value is a 0-, 1-, 2-, or 3-digit octal number.- Note: The bsh, ksh, and csh commands each contain a built-in echo subcommand. The echo command
and the bsh and ksh echo subcommands work the same way. The csh echo subcommand does not work the same way as the echo command.
The \ (backslash) is a quote character in the shell. This means that unless the \ is used with an escape character or enclosed in quotes, for example "\" or '\', the shell removes the backslashes when the command is expanded.
After shell expansion, the echo command writes the output based on the escape sequences in the input. Refer to the Backslash Reduction table for an example comparison of how backslashes in a command are first reduced by the shell and then by the echo command:
Backslash Reduction
| Command Entered | After Shell Expansion | After echo Command Processing |
|---|---|---|
echo hi\\\\there |
echo hi\\there |
hi\there |
echo 'hi\\\\there' |
echo 'hi\\\\there' |
hi\\there |
echo "hi\\\\there' |
echo "hi\\there" |
hi\there |
종료 상태
| 값 | 뜻 |
|---|---|
| 0 | 잘 끝났습니다. |
| 0보다 큼 | 오류가 났습니다. |
영어 원문
This command returns the following exit values:
- 0 — Successful completion.
>0— An error occurred.
예제
- 표준 출력에 메시지를 씁니다.
echo Please insert diskette . . .
- 특수 문자가 든 메시지를 표시합니다. 세 줄을 건너뛴 뒤 메시지를 두 줄로 보여 줍니다. 이스케이프 시퀀스가 들어 있으면 메시지를 따옴표로 감싸야 합니다. 그렇지 않으면 셸이
\(백슬래시)를 메타 문자로 보고 다르게 다룹니다.
echo "\n\n\nI'm at lunch.\nI'll be back at 1:00."
I'm at lunch.
I'll be back at 1:00.
- 패턴 일치 문자와 함께 씁니다.
The back-up files are:뒤에 현재 디렉터리에서.bak로 끝나는 파일 이름을 표시합니다.
echo The back-up files are: *.bak
- 파일에 한 줄을 더합니다. 셸이
PATH셸 변수의 값을 바꿔 넣은 뒤 메시지를notes파일 끝에 더합니다.
echo Remember to set the shell search path to $PATH. >>notes
- 표준 오류에 메시지를 씁니다. 오류 메시지를 표준 오류로 재지정합니다.
>&2를 빼면 표준 출력에 씁니다.
echo Error: file already exists. >&2
영어 원문
To write a message to standard output, enter:
echo Please insert diskette . . .To display a message containing special characters, enter:
echo "\n\n\nI’m at lunch.\nI’ll be back at 1:00."
This skips three lines and displays the message: I’m at lunch. I’ll be back at 1:00.
Note: You must put the message in quotation marks if it contains escape sequences. Otherwise, the shell interprets the \ (backslash) as a metacharacter and treats the \ differently.
- To use the echo command with pattern-matching characters, enter:
echo The back-up files are: *.bak
This usage displays the message The back-up files are: followed by the file names in the current directory ending with .bak.
- To add a single line of text to a file, enter:
echo Remember to set the shell search path to $PATH. >>notes
This usage adds the message to the end of the file notes after the shell substitutes the value of the PATH shell variable.
- To write a message to the standard error output, enter:
echo Error: file already exists. >&2
This command redirects the error message to standard error. If the >&2 is omitted, the message is written to standard output.
파일
| 파일 | 설명 |
|---|---|
/usr/bin/echo |
echo 명령이 들어 있습니다. |
관련 명령어: bsh, ksh, printf
영어 원문
- /usr/bin/echo — Contains the echo command.
Related information:
- bsh command
- ksh command
- printf command
- Input and output redirection
리눅스(GNU)와 다른 점
| 항목 | AIX 5.3·6.1 | 리눅스 bash·GNU echo |
|---|---|---|
-n, -e, -E |
플래그를 받지 않아 글자 그대로 출력 | 플래그로 해석 |
이스케이프(\n 등) |
늘 해석 | bash 내장은 -e를 줘야 해석 |
| 줄바꿈 생략 | \c |
-n |
셸과 시스템마다 echo의 동작이 달라 이식성이 필요한 스크립트에서는 printf를 쓰는 것이 안전합니다.