[AIX 운영 체제와 장치 관리 20] Korn 셸 (1) — 셸 변수, 명령 치환, 산술 평가, 필드 분리, 내장 명령, 조건식, 따옴표

핵심 정리

  • 셸이 설정하는 변수(_, ERRNO, LINENO, OLDPWD, OPTARG, OPTIND, PPID, PWD, RANDOM, REPLY, SECONDS)와 셸이 쓰는 변수(CDPATH, ENV, FCEDIT, HISTFILE, HISTSIZE, IFS, MAILCHECK, PATH, PS1~PS4, TMOUT 등)를 구분합니다. HISTSIZE 기본은 일반 사용자 128, root 512입니다.
  • 명령 치환은 $(command)를 권장하며(역따옴표는 구식), 끝의 줄 바꿈을 지우므로 보존하려면 큰따옴표로 감쌉니다. $((식))은 산술 치환입니다.
  • let과 (( ))는 C 언어와 같은 우선순위의 정수 산술을 하며 ++, --, ?:, 쉼표는 지원하지 않습니다. typeset -i로 정수 매개변수를 만듭니다.
  • [[ ]] 안에서는 단어 분리와 파일 이름 치환을 하지 않으며, 파일 검사(-a~-x, -L·-O·-G·-S, -nt·-ot·-ef), 문자열·패턴 비교, 산술 비교(-eq 등)를 씁니다.
  • 작은따옴표는 모든 문자를 그대로 두고, 큰따옴표는 달러 기호·역따옴표·백슬래시만 특별하게 남깁니다. 따옴표 안의 "$@"는 "$1" "$2" ..., "$*"는 IFS 첫 문자로 이은 한 단어입니다.
항목 내용
버전 AIX 6.1 (5.3판과 거의 같음)
원문 Operating system and device management — 5.3판 404416쪽, 6.1판 205213쪽
관련 명령어 ksh, let, typeset -i, set, cd, fc, getopts, read, print, ulimit, umask, whence
관련 파일 $HOME/.sh_history, /etc/security/limits

Korn 셸(ksh 명령)은 Bourne 셸(bsh 명령)과 하위 호환되며, Bourne 셸 기능 대부분과 C 셸의 좋은 기능 몇 가지를 갖추고 있습니다.

Korn 셸이나 POSIX 셸이 설정하는 변수

다음은 셸이 설정하는 변수입니다.

변수 설명
_(밑줄) 처음에는 환경으로 넘어온, 실행 중인 셸이나 스크립트의 절대 경로 이름입니다. 이후에는 앞 명령의 마지막 인수가 할당됩니다. 비동기 명령에는 설정되지 않습니다. 메일을 확인할 때 일치하는 MAIL 파일 이름을 담는 데도 씁니다.
ERRNO 가장 최근에 실패한 서브루틴이 설정한 값. 시스템에 따라 다르며 디버깅용입니다.
LINENO 실행 중인 스크립트나 함수 안에서 현재 줄의 번호
OLDPWD cd 명령이 설정한 이전 작업 디렉터리
OPTARG getopts 일반 내장 명령이 처리한 마지막 옵션 인수의 값
OPTIND getopts 일반 내장 명령이 처리한 마지막 옵션 인수의 색인
PPID 셸의 부모 프로세스 번호
PWD cd 명령이 설정한 현재 작업 디렉터리
RANDOM 0부터 32767 사이에 고르게 분포한 난수 정수를 만듭니다. RANDOM 변수에 숫자 값을 할당하면 난수 순서를 초기화할 수 있습니다.
REPLY select 문과, 인수 없이 쓴 read 일반 내장 명령이 설정합니다.
SECONDS 셸을 호출한 뒤 지난 초 수를 돌려줍니다. 이 변수에 값을 할당하면 참조할 때 할당한 값에 할당 뒤 지난 초 수를 더한 값을 돌려줍니다.

Korn 셸이나 POSIX 셸이 쓰는 변수

다음은 셸이 쓰는 변수입니다.

변수 설명
CDPATH cd(디렉터리 변경) 명령의 검색 경로
COLUMNS 셸 편집 모드의 편집 창 너비와 select 목록 출력 너비
EDITOR 값이 emacs, gmacs, vi로 끝나고 VISUAL 변수가 set 특수 내장 명령으로 설정되지 않았으면 해당 옵션이 켜집니다.
ENV 설정돼 있으면 값에 매개변수 치환을 해서 셸을 호출할 때 실행할 스크립트의 경로 이름을 만듭니다. 이 파일은 보통 별명과 함수 정의에 씁니다. 비대화식 셸에서는 무시됩니다.
FCEDIT fc 일반 내장 명령의 기본 편집기 이름
FPATH 함수 정의를 찾는 검색 경로. -u 플래그가 붙은 함수를 참조하거나 명령을 찾지 못하면 이 경로를 찾습니다. 실행 파일을 찾으면 읽어 현재 환경에서 실행합니다.
HISTFILE 셸을 호출할 때 설정돼 있으면 명령 기록을 저장할 파일의 경로 이름입니다. 일부 시작 파일이 사용자가 HISTFILE과 HISTSIZE에 지정한 설정을 사실상 앞지르는 명령을 담고 있을 수 있어, 기록 파일의 초기화는 시스템 시작 파일에 좌우될 수 있습니다. 예를 들어 함수 정의 명령은 기록 파일에 기록됩니다. 시스템 관리자가 ENV 파일보다, 또는 HISTFILE·HISTSIZE 변수 설정보다 먼저 호출되는 시스템 시작 파일에 함수 정의를 넣으면 사용자가 손대기 전에 기록 파일이 초기화됩니다.
HISTSIZE 셸을 호출할 때 설정돼 있으면 이 셸이 접근할 수 있는 이전 명령 수가 이 수 이상이 됩니다. 기본값은 일반 사용자 128개, root 사용자 512개입니다.
HOME 로그인 디렉터리 이름으로, 로그인이 끝나면 현재 디렉터리가 됩니다. login 프로그램이 초기화합니다. cd 명령은 $HOME 값을 기본값으로 씁니다. 셸 프로시저에서 명시적 경로 대신 이 변수를 쓰면 고치지 않고 다른 디렉터리에서 실행할 수 있습니다.
IFS 내부 필드 구분자. 보통 스페이스, 탭, 줄 바꿈이며 명령이나 매개변수 치환 결과의 단어를 나누고 read 일반 내장 명령에서 단어를 나누는 데 씁니다. IFS의 첫 문자는 $* 치환의 인수를 구분하는 데 씁니다.
LANG LC_* 변수의 기본값
LC_ALL LANG과 LC_* 변수 값보다 우선합니다.
LC_COLLATE 패턴 일치 안의 범위 식 동작을 정합니다.
LC_CTYPE 문자 분류, 대소문자 변환, 그 밖의 문자 속성을 정합니다.
LC_MESSAGES 메시지를 쓸 언어를 정합니다.
LINES select 목록을 출력할 열 길이(원문 그대로, 줄 수). select 목록은 LINES 변수로 지정한 줄의 약 3분의 2가 찰 때까지 세로로 출력됩니다.
MAIL 메일 시스템이 새 메일 도착을 감지하는 데 쓰는 파일 경로 이름. 메일 파일 이름으로 설정하고 MAILPATH가 설정되지 않았으면 셸은 지정한 파일에 새 메일이 오면 알립니다.
MAILCHECK 셸이 MAILPATH나 MAIL 변수로 지정한 파일의 수정 시각 변화를 확인하는 간격(초). 기본값은 600초입니다. 시간이 지나면 셸은 다음 프롬프트를 내기 전에 확인합니다.
MAILPATH 콜론으로 구분한 파일 이름 목록. 설정돼 있으면 MAILCHECK로 지정한 기간 동안 지정한 파일에 생긴 변화를 알립니다. 각 파일 이름 뒤에 ?와 출력할 메시지를 붙일 수 있습니다. 메시지에는 변수 치환이 일어나며 $_는 바뀐 파일 이름입니다. 기본 메시지는 you have mail in $_입니다.
NLSPATH LC_MESSAGES 처리를 위한 메시지 카탈로그 위치
PATH 명령 검색 경로. 콜론으로 구분한 디렉터리 경로 이름의 순서 목록입니다. 셸은 명령을 찾을 때 이 디렉터리를 지정한 순서대로 찾습니다. 목록 어디에든 있는 빈 문자열은 현재 디렉터리를 뜻합니다.
PS1 1차 시스템 프롬프트 문자열. 매개변수 치환을 거쳐 1차 프롬프트 문자열이 되며 기본값은 $입니다. 1차 프롬프트 문자열의 !는 명령 번호로 바뀝니다.
PS2 2차 프롬프트 문자열. 기본값은 >입니다.
PS3 select 반복 안에서 쓰는 선택 프롬프트 문자열. 기본값은 #?입니다.
PS4 매개변수 치환을 거쳐 실행 추적의 각 줄 앞에 붙습니다. 생략하면 실행 추적 프롬프트는 +입니다.
SHELL 셸의 경로 이름. 환경에 유지됩니다.
SHELL PROMPT 대화식으로 쓸 때 셸은 명령을 읽기 전에 PS1 값으로 프롬프트를 냅니다. 언제든 새 줄이 입력됐는데 명령을 끝내려면 입력이 더 필요하면 2차 프롬프트(PS2 값)를 냅니다.
TMOUT 셸이 끝나기 전에 입력 없이 기다리는 초 수. 0보다 큰 값으로 설정하면 PS1 프롬프트를 낸 뒤 정한 시간 안에 명령이 입력되지 않으면 셸이 끝납니다(셸은 이 값의 상한을 넣어 컴파일될 수 있습니다). 참고: 제한 시간이 지난 뒤 셸이 끝나기까지 60초를 기다립니다.
VISUAL 값이 emacs, gmacs, vi로 끝나면 해당 옵션이 켜집니다.

셸은 PATH, PS1, PS2, MAILCHECK, TMOUT, IFS 매개변수에 기본값을 주지만 HOME, SHELL, ENV, MAIL 매개변수는 설정하지 않습니다(HOME 매개변수는 login 명령이 설정합니다).

Korn 셸이나 POSIX 셸의 명령 치환

Korn 셸(POSIX 셸)에서는 명령 치환을 할 수 있습니다. 명령 치환에서 셸은 지정한 명령을 서브셸 환경에서 실행하고 그 명령을 출력으로 바꿉니다.

Korn 셸이나 POSIX 셸에서 명령 치환을 하려면 다음을 입력합니다.

text
$(command)

역따옴표 형식이라면 다음을 입력합니다.

text
`command`

참고: ksh는 역따옴표 구문도 받지만, X/Open Portability Guide Issue 4와 POSIX 표준은 이를 구식으로 봅니다. 이 표준은 이식 가능한 응용 프로그램에 $(command) 구문을 쓰도록 권합니다.

셸은 서브셸 환경에서 command를 실행하고, 명령 치환(command 텍스트와 둘러싼 $( )나 역따옴표)을 명령의 표준 출력으로 바꿔 펼칩니다. 이때 치환 끝의 줄 바꿈 문자 연속은 지웁니다.

다음 예에서 명령을 둘러싼 $( )는 whoami 명령의 출력으로 치환한다는 뜻입니다.

text
echo My name is: $(whoami)

같은 명령 치환을 다음처럼 할 수도 있습니다.

text
echo My name is: `whoami`

사용자 dee에게 두 예의 출력은 다음과 같습니다.

text
My name is: dee

산술 식을 ( )로 감싸 치환할 수도 있습니다. 예를 들어 다음 명령은

text
echo Each hour contains $((60 * 60)) seconds

다음 결과를 냅니다.

text
Each hour contains 3600 seconds

Korn 셸이나 POSIX 셸은 명령 치환을 할 때 끝의 줄 바꿈 문자를 모두 지웁니다. 예를 들어 현재 디렉터리에 file1, file2, file3 파일이 있으면 다음 명령은

text
echo $(ls)

줄 바꿈 문자를 지우고 다음 출력을 냅니다.

text
file1 file2 file3

줄 바꿈 문자를 보존하려면 치환한 명령을 " " 안에 넣습니다.

text
echo "$(ls)"

Korn 셸이나 POSIX 셸의 산술 평가

Korn 셸이나 POSIX 셸의 일반 내장 명령 let으로 정수 산술을 할 수 있습니다.

상수는 [Base#]Number 형식입니다. Base 매개변수는 2부터 36까지의 십진수로 산술 진법을 나타냅니다. Number 매개변수는 그 진법의 수입니다. Base 매개변수를 생략하면 셸은 10진법을 씁니다.

산술 식은 C 프로그래밍 언어와 같은 구문, 우선순위, 결합 방향을 씁니다. 이중 더하기(++), 이중 하이픈(--), 물음표-콜론(?:), 쉼표(,)를 뺀 모든 정수 연산자를 지원합니다. 다음은 올바른 Korn 셸이나 POSIX 셸 연산자를 우선순위가 높은 것부터 나열한 것입니다.

  • - — 단항 마이너스
  • ! — 논리 부정
  • ~ — 비트 부정
  • * — 곱하기
  • / — 나누기
  • % — 나머지
  • + — 더하기
  • - — 빼기
  • <<, >> — 왼쪽 시프트, 오른쪽 시프트
  • <=, >=, <, >, ==, != — 비교
  • & — 비트 AND
  • ^ — 비트 배타적 OR
  • | — 비트 OR
  • && — 논리 AND
  • || — 논리 OR
  • =, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |= — 할당

*, &, <, > 같은 많은 산술 연산자는 Korn 셸이나 POSIX 셸에 특별한 뜻이 있습니다. 이런 문자는 따옴표로 감싸야 합니다. 예를 들어 y의 현재 값에 5를 곱해 y에 다시 할당하려면 다음 식을 씁니다.

text
let "y = y * 5"

식을 따옴표로 감싸면 * 문자의 특별한 뜻이 사라집니다.

let 명령 식 안에서 연산을 괄호로 묶어 계산 순서를 정할 수 있습니다. 예를 들어 다음 식에서

text
let "z = q * (z - 10)"

명령은 q에 z에서 10을 뺀 값을 곱합니다.

Korn 셸이나 POSIX 셸에는 식을 하나만 평가할 때 쓰는 let 명령의 다른 형식이 있습니다. 셸은 (( ))로 감싼 명령을 따옴표로 감싼 식으로 취급합니다. 그래서 다음 식은

text
((x = x / 3))

다음과 같습니다.

text
let "x = x / 3"

이름 있는 매개변수는 산술 식 안에서 매개변수 치환 구문 없이 이름으로 참조합니다. 이름 있는 매개변수를 참조하면 그 값을 산술 식으로 평가합니다.

typeset 특수 내장 명령의 -i 플래그로 이름 있는 매개변수의 내부 정수 표현을 지정합니다. -i 플래그를 쓰면 이름 있는 매개변수에 할당할 때마다 값에 산술 평가를 합니다. 산술 진법을 지정하지 않으면 매개변수에 처음 할당한 값이 진법을 정합니다. 이 진법은 매개변수 치환이 일어날 때 씁니다.

관련 개념

  • Korn 셸 또는 POSIX 셸 명령 — Korn 셸은 대화식 명령 해석기이자 명령 프로그래밍 언어이며 POSIX를 따릅니다.
  • Korn 셸의 매개변수

Korn 셸이나 POSIX 셸의 필드 분리

명령 치환을 한 뒤 Korn 셸은 치환 결과에서 IFS(내부 필드 구분자) 변수에 있는 필드 구분 문자를 찾습니다. 그런 문자를 찾으면 셸은 치환 결과를 서로 다른 인수로 나눕니다.

셸은 명시적인 빈 인수(""나 '')는 유지하고, 암시적인 빈 인수(값이 없는 매개변수에서 생긴 것)는 지웁니다.

  • IFS 값이 스페이스, 탭, 줄 바꿈 문자이거나 설정되지 않았으면, 입력 처음이나 끝의 스페이스·탭·줄 바꿈 문자 연속은 무시되고, 입력 안의 그런 문자 연속은 필드를 구분합니다. 예를 들어 다음 입력은 school과 days 두 필드가 됩니다.
text
<newline><space><tab>school<tab><tab>days<space>
  • 그렇지 않고 IFS 값이 비어 있지 않으면 다음 규칙을 차례로 적용합니다. IFS 공백은 IFS 값에 든 공백 문자의 연속(0개 이상)을 뜻합니다(예를 들어 IFS에 스페이스·쉼표·탭이 들어 있으면 스페이스와 탭 문자의 연속이 IFS 공백입니다).
    1. 입력 처음과 끝의 IFS 공백은 무시합니다.
    2. 입력에서 IFS 공백이 아닌 IFS 문자가 나올 때마다, 이웃한 IFS 공백과 함께 필드를 구분합니다.
    3. 길이가 0이 아닌 IFS 공백은 필드를 구분합니다.

Korn 셸이나 POSIX 셸의 특수 내장 명령 목록

특수 명령은 Korn 셸과 POSIX 셸에 내장돼 셸 프로세스 안에서 실행됩니다.

명령 설명
:(콜론) 인수를 펼치기만 합니다.
.(점) 지정한 파일을 읽고 그 명령을 실행합니다.
break 둘러싼 for, while, until, select 반복이 있으면 빠져나갑니다.
continue 둘러싼 for, while, until, select 반복의 다음 반복으로 넘어갑니다.
eval 인수를 셸 입력으로 읽고 결과 명령을 실행합니다.
exec 새 프로세스를 만들지 않고 이 셸 대신 Argument 매개변수로 지정한 명령을 실행합니다.
exit n 매개변수로 지정한 종료 상태로 셸을 끝냅니다.
export 이후 실행하는 명령의 환경으로 자동으로 내보낼 이름을 표시합니다.
newgrp exec /usr/bin/newgrp [Group ...] 명령과 같습니다.
readonly 지정한 이름을 읽기 전용으로 표시합니다.
return 셸을 호출한 스크립트로 돌아가게 합니다.
set 옵션이나 인수를 주지 않으면 모든 셸 변수의 이름과 값을 현재 로케일의 정렬 순서로 씁니다.
shift 위치 매개변수의 번호를 다시 매깁니다.
times 셸과 셸에서 실행한 프로세스의 누적 사용자·시스템 시간을 출력합니다.
trap 셸이 지정한 신호를 받으면 지정한 명령을 실행합니다.
typeset 셸 매개변수의 속성과 값을 설정합니다.
unset 지정한 매개변수의 값과 속성을 해제합니다.

관련 개념

  • Korn 셸이나 POSIX 셸 내장 명령

Korn 셸이나 POSIX 셸의 일반 내장 명령

다음은 Korn 셸이나 POSIX 셸의 일반 내장 명령 목록입니다.

명령 설명
alias 별명 목록을 표준 출력에 출력합니다.
bg 지정한 작업을 백그라운드로 보냅니다.
cd 현재 디렉터리를 지정한 디렉터리로 바꾸거나 현재 문자열을 지정한 문자열로 치환합니다.
echo 문자열을 표준 출력에 씁니다.
fc 터미널에서 입력한 마지막 HISTSIZE개 명령 가운데 범위를 고릅니다. 이전→새 치환을 한 뒤 지정한 명령을 다시 실행합니다.
fg 지정한 작업을 포그라운드로 가져옵니다.
getopts Argument 매개변수에서 올바른 옵션을 확인합니다.
jobs 지정한 작업의 정보를 나열합니다.
kill 지정한 작업이나 프로세스에 TERM(종료) 신호를 보냅니다.
let 지정한 산술 식을 평가합니다.
print 셸 출력을 출력합니다.
pwd print -r - $PWD 명령과 같습니다.
read 셸 입력을 받습니다.
ulimit /etc/security/limits 파일에 정의한 사용자 프로세스 자원 한도를 설정하거나 보여 줍니다.
umask 파일 권한을 정합니다.
unalias 이름 목록의 매개변수를 별명 목록에서 지웁니다.
wait 지정한 작업을 기다리고 종료합니다.
whence 지정한 각 이름을 명령 이름으로 쓰면 어떻게 해석될지 알려 줍니다.

자세한 내용은 Korn 셸이나 POSIX 셸 내장 명령을 봅니다.

Korn 셸이나 POSIX 셸의 조건식

조건식은 [[ 복합 명령과 함께 써서 파일 속성을 시험하고 문자열을 비교합니다.

[[와 ]] 사이에 나오는 단어에는 단어 분리와 파일 이름 치환을 하지 않습니다. 각 식은 다음 단항이나 이항 식 하나 이상으로 이루어집니다.

식 참이 되는 조건
-a File 지정한 파일이 존재하는 다른 파일을 가리키는 심볼릭 링크이면 참(원문 그대로. 일반적으로는 파일이 존재하면 참)
-b File 지정한 파일이 있고 블록 특수 파일이면 참
-c File 지정한 파일이 있고 문자 특수 파일이면 참
-d File 지정한 파일이 있고 디렉터리이면 참
-e File 지정한 파일이 있으면 참
-f File 지정한 파일이 있고 일반 파일이면 참
-g File 지정한 파일이 있고 setgid 비트가 설정돼 있으면 참
-h File 지정한 파일이 있고 심볼릭 링크이면 참
-k File 지정한 파일이 있고 sticky 비트가 설정돼 있으면 참
-n String 지정한 문자열의 길이가 0이 아니면 참
-o Option 지정한 옵션이 켜져 있으면 참
-p File 지정한 파일이 있고 FIFO 특수 파일이나 파이프이면 참
-r File 지정한 파일이 있고 현재 프로세스가 읽을 수 있으면 참
-s File 지정한 파일이 있고 크기가 0보다 크면 참
-t FileDescriptor 지정한 파일 기술자 번호가 열려 있고 터미널 장치와 연결돼 있으면 참
-u File 지정한 파일이 있고 setuid 비트가 설정돼 있으면 참
-w File 지정한 파일이 있고 쓰기 비트가 켜져 있으면 참. 그러나 이 시험이 참이어도 읽기 전용 파일 시스템의 파일에는 쓸 수 없습니다.
-x File 지정한 파일이 있고 실행 플래그가 켜져 있으면 참. 지정한 파일이 있고 디렉터리이면 현재 프로세스에 그 디렉터리를 검색할 권한이 있다는 뜻입니다.
-z String 지정한 문자열의 길이가 0이면 참
-L File 지정한 파일이 있고 심볼릭 링크이면 참
-O File 지정한 파일이 있고 이 프로세스의 유효 사용자 ID가 소유하면 참
-G File 지정한 파일이 있고 그룹이 이 프로세스의 유효 그룹 ID와 같으면 참
-S File 지정한 파일이 있고 소켓이면 참
File1 -nt File2 File1이 있고 File2보다 새로우면 참
File1 -ot File2 File1이 있고 File2보다 오래됐으면 참
File1 -ef File2 File1과 File2가 있고 같은 파일을 가리키면 참
String1 = String2 String1이 String2와 같으면 참
String1 != String2 String1이 String2와 다르면 참
String = Pattern 지정한 문자열이 지정한 패턴과 맞으면 참
String != Pattern 지정한 문자열이 지정한 패턴과 맞지 않으면 참
String1 < String2 문자의 ASCII 값으로 String1이 String2보다 앞이면 참
String1 > String2 문자의 ASCII 값으로 String1이 String2보다 뒤면 참
Expression1 -eq Expression2 Expression1이 Expression2와 같으면 참
Expression1 -ne Expression2 Expression1이 Expression2와 다르면 참
Expression1 -lt Expression2 Expression1이 Expression2보다 작으면 참
Expression1 -gt Expression2 Expression1이 Expression2보다 크면 참
Expression1 -le Expression2 Expression1이 Expression2보다 작거나 같으면 참
Expression1 -ge Expression2 Expression1이 Expression2보다 크거나 같으면 참

참고: 앞의 각 식에서 File 변수가 /dev/fd/n(n은 정수)과 같은 꼴이면, 기술자 번호가 n인 열린 파일에 시험을 적용합니다.

이 기본 식이나 더 작은 부분으로 다음 식을 써서 복합 식을 만들 수 있습니다. 우선순위가 높은 것부터 나열합니다.

  • (Expression) — 지정한 식이 참이면 참. 식을 묶는 데 씁니다.
  • ! Expression — 지정한 식이 거짓이면 참
  • Expression1 && Expression2 — Expression1과 Expression2가 모두 참이면 참
  • Expression1 || Expression2 — Expression1이나 Expression2 가운데 하나라도 참이면 참

Korn 셸이나 POSIX 셸의 문자 따옴표

Korn 셸이나 POSIX 셸이 문자를 보통 붙는 뜻 없이 일반 문자로 읽게 하려면 따옴표로 감싸야 합니다.

메타 문자마다 셸에 특별한 뜻이 있으며, 따옴표로 감싸지 않으면 단어를 끝냅니다. Korn 셸이나 POSIX 셸은 다음 문자를 메타 문자로 보며, 문자 그대로 나타내려면 따옴표로 감싸야 합니다.

  • 파이프(|)
  • 앰퍼샌드(&)
  • 세미콜론(;)
  • 작다 기호(<)와 크다 기호(>)
  • 여는 괄호(()와 닫는 괄호())
  • 달러 기호($)
  • 역따옴표와 작은따옴표(')
  • 백슬래시(\)
  • 큰따옴표(")
  • 줄 바꿈 문자
  • 스페이스 문자
  • 탭 문자

메타 문자의 특별한 뜻을 없애려면 다음 따옴표 방식 가운데 하나를 씁니다.

  • 백슬래시 — 따옴표로 감싸지 않은 백슬래시(\)는 다음 문자의 글자 그대로의 값을 보존합니다. 단 줄 바꿈 문자는 예외입니다. 백슬래시 뒤에 줄 바꿈 문자가 오면 셸은 줄이 이어진다고 해석합니다.
  • 작은따옴표 — 문자를 작은따옴표(' ')로 감싸면 그 안의 모든 문자의 글자 그대로의 값을 보존합니다. 작은따옴표 안에는 작은따옴표가 올 수 없습니다. 작은따옴표로 감싼 문자열 안에서는 백슬래시로 작은따옴표를 이스케이프할 수 없습니다. 작은따옴표를 넣으려면 예를 들어 'a'\''b'처럼 쓰며, 결과는 a'b입니다.
  • 큰따옴표 — 문자를 큰따옴표(" ")로 감싸면 그 안의 모든 문자의 글자 그대로의 값을 보존하되, 달러 기호, 역따옴표, 백슬래시는 다음과 같이 예외입니다.
    • 달러 기호($)는 매개변수 펼치기, 명령 치환의 한 형식, 산술 펼치기를 시작한다는 특별한 뜻을 유지합니다. 따옴표 문자열 안에서 $(와 짝이 맞는 ) 사이에 든 입력 문자는 큰따옴표의 영향을 받지 않고, 단어를 펼칠 때 $(...)를 대신할 출력을 내는 명령을 정의합니다. ${부터 짝이 맞는 }까지의 문자열 안에는 이스케이프하지 않은 큰따옴표나 작은따옴표가 있다면 짝수 개여야 합니다. 글자 그대로의 {나 }는 앞에 백슬래시를 붙여 이스케이프해야 합니다.
    • 역따옴표는 명령 치환의 다른 형식을 시작한다는 특별한 뜻을 유지합니다. 따옴표 문자열에서 첫 역따옴표부터 백슬래시가 앞에 없는 다음 역따옴표까지가, 단어를 펼칠 때 그 부분을 대신할 출력을 내는 명령을 정의합니다.
    • 백슬래시(\)는 다음 문자 앞에서만 이스케이프 문자라는 특별한 뜻을 유지합니다. 달러 기호, 역따옴표, 큰따옴표, 백슬래시, 줄 바꿈 문자.

큰따옴표 안에 큰따옴표를 넣으려면 앞에 백슬래시를 붙여야 합니다. 큰따옴표를 쓸 때 백슬래시 바로 뒤에 특별한 뜻으로 해석될 문자가 오면 백슬래시는 지워지고 뒤 문자는 글자 그대로 취급됩니다. 백슬래시 뒤에 특별한 뜻을 가질 문자가 오지 않으면 백슬래시는 바뀌지 않고 남으며 바로 뒤 문자도 바뀌지 않습니다. 예:

text
"\$"    ->      $
"\a"    ->      \a

Korn 셸이나 POSIX 셸의 메타 문자와 따옴표 문자에는 다음 조건이 적용됩니다.

  • 따옴표로 감싸지 않았을 때, 매개변수 할당 값으로 쓸 때, 파일 이름으로 쓸 때 $*와 $@의 뜻은 같습니다.
  • 명령 인수로 쓸 때 "$*"는 "$1d$2d..."와 같으며, d는 IFS 매개변수의 첫 문자입니다.
  • "$@"는 "$1" "$2" ...와 같습니다.
  • 역따옴표 안에서 백슬래시는 백슬래시(\), 작은따옴표('), 달러 기호($) 문자를 따옴표 처리합니다. 역따옴표가 큰따옴표(" ") 안에 있으면 백슬래시는 큰따옴표 문자도 따옴표 처리합니다.
  • 매개변수와 명령 치환은 큰따옴표(" ") 안에서 일어납니다.
  • 예약어의 아무 문자나 따옴표로 감싸면 예약어나 별명의 특별한 뜻이 사라집니다. 함수 이름이나 내장 명령 이름은 따옴표로 감쌀 수 없습니다.
영어 원문

Korn shell

The Korn shell (ksh command) is backwardly compatible with the Bourne shell (bsh command) and contains most of the Bourne shell features as well as several of the best features of the C shell.

Variables set by the Korn shell or POSIX shell

The following are variables that are set by the shell.

  • underscore (_) — Indicates initially the absolute path name of the shell or script being executed as passed in the environment. Subsequently, it is assigned the last argument of the previous command. This parameter is not set for commands that are asynchronous. This parameter is also used to hold the name of the matching MAIL file when checking for mail.
  • ERRNO — Specifies a value that is set by the most recently failed subroutine. This value is system-dependent and is intended for debugging purposes.
  • LINENO — Specifies the line number of the current line within the script or function being executed.
  • OLDPWD — Indicates the previous working directory set by the cd command.
  • OPTARG — Specifies the value of the last option argument processed by the getopts regular built-in command.
  • OPTIND — Specifies index of the last option argument processed by the getopts regular built-in command.
  • PPID — Identifies the process number of the parent of the shell.
  • PWD — Indicates the present working directory set by the cd command.
  • RANDOM — Generates a random integer, uniformly distributed between 0 and 32767. The sequence of random numbers can be initialized by assigning a numeric value to the RANDOM variable.
  • REPLY — Set by the select statement and by the read regular built-in command when no arguments are supplied.
  • SECONDS — Specifies the number of seconds since shell invocation is returned. If this variable is assigned a value, then the value returned upon reference will be the value that was assigned plus the number of seconds since the assignment.

Variables used by the Korn shell or POSIX shell

The following are variables that are used by the shell.

  • CDPATH — Indicates the search path for the cd (change directory) command.
  • COLUMNS — Defines the width of the edit window for the shell edit modes and for printing select lists.
  • EDITOR — If the value of this parameter ends in emacs, gmacs, or vi, and the VISUAL variable is not set with the set special built-in command, then the corresponding option is turned on.
  • ENV — If this variable is set, then parameter substitution is performed on the value to generate the path name of the script that will be executed when the shell is invoked. This file is typically used for alias and function definitions. This variable will be ignored for noninteractive shells.
  • FCEDIT — Specifies the default editor name for the fc regular built-in command.
  • FPATH — Specifies the search path for function definitions. This path is searched when a function with the -u flag is referenced and when a command is not found. If an executable file is found, then it is read and executed in the current environment.
  • HISTFILE — If this variable is set when the shell is invoked, then the value is the path name of the file that will be used to store the command history. The initialization process for the history file can be dependent on the system start-up files because some start-up files can contain commands that effectively preempt the settings the user has specified for HISTFILE and HISTSIZE. For example, function definition commands are recorded in the history file. If the system administrator includes function definitions in a system start-up file that is called before the ENV file or before HISTFILE or HISTSIZE variable is set, the history file is initialized before the user can influence its characteristics.
  • HISTSIZE — If this variable is set when the shell is invoked, then the number of previously entered commands that are accessible by this shell will be greater than or equal to this number. The default is 128 commands for nonroot users and 512 commands for the root user.
  • HOME — Indicates the name of your login directory, which becomes the current directory upon completion of a login. The login program initializes this variable. The cd command uses the value of the $HOME parameter as its default value. Using this variable rather than an explicit path name in a shell procedure allows the procedure to be run from a different directory without alterations.
  • IFS — Specifies IFS (internal field separators), which are normally space, tab, and newline, used to separate command words that result from command or parameter substitution and for separating words with the regular built-in command read. The first character of the IFS parameter is used to separate arguments for the $* substitution.
  • LANG — Provides a default value for the LC_* variables.
  • LC_ALL — Overrides the value of the LANG and LC_* variables.
  • LC_COLLATE — Determines the behavior of range expression within pattern matching.
  • LC_CTYPE — Defines character classification, case conversion, and other character attributes.
  • LC_MESSAGES — Determines the language in which messages are written.
  • LINES — Determines the column length for printing select lists. Select lists print vertically until about two-thirds of lines specified by the LINES variable are filled.
  • MAIL — Specifies the file path name used by the mail system to detect the arrival of new mail. If this variable is set to the name of a mail file and the MAILPATH variable is not set, then the shell informs the user of new mail in the specified file.
  • MAILCHECK — Specifies how often (in seconds) the shell checks for changes in the modification time of any of the files specified by the MAILPATH or MAIL variables. The default value is 600 seconds. When the time has elapsed, the shell checks before issuing the next prompt.
  • MAILPATH — Specifies a list of file names separated by colons. If this variable is set, then the shell informs the user of any modifications to the specified files that have occurred during the period, in seconds, specified by the MAILCHECK variable. Each file name can be followed by a ? and a message that will be printed. The message will undergo variable substitution with the $_ variable defined as the name of the file that has changed. The default message is you have mail in $_.
  • NLSPATH — Determines the location of message catalogs for the processing of LC_MESSAGES.
  • PATH — Indicates the search path for commands, which is an ordered list of directory path names separated by colons. The shell searches these directories in the specified order when it looks for commands. A null string anywhere in the list represents the current directory.
  • PS1 — Specifies the string to be used as the primary system prompt. The value of this parameter is expanded for parameter substitution to define the primary prompt string, which is a $ by default. The ! character in the primary prompt string is replaced by the command number.
  • PS2 — Specifies the value of the secondary prompt string, which is a > by default.
  • PS3 — Specifies the value of the selection prompt string used within a select loop, which is #? by default.
  • PS4 — The value of this variable is expanded for parameter substitution and precedes each line of an execution trace. If omitted, the execution trace prompt is a +.
  • SHELL — Specifies the path name of the shell, which is kept in the environment.
  • SHELL PROMPT — When used interactively, the shell prompts with the value of the PS1 parameter before reading a command. If at any time a new line is entered and the shell requires further input to complete a command, the shell issues the secondary prompt (the value of the PS2 parameter).
  • TMOUT — Specifies the number of seconds a shell waits inactive before exiting. If the TMOUT variable is set to a value greater than zero (0), the shell exits if a command is not entered within the prescribed number of seconds after issuing the PS1 prompt. (Note that the shell can be compiled with a maximum boundary that cannot be exceeded for this value.) Note: After the timeout period has expired, there is a 60-second pause before the shell exits.
  • VISUAL — If the value of this variable ends in emacs, gmacs, or vi, then the corresponding option is turned on.

The shell gives default values to the PATH, PS1, PS2, MAILCHECK, TMOUT, and IFS parameters, but the HOME, SHELL, ENV, and MAIL parameters are not set by the shell (although the HOME parameter is set by the login command).

Command substitution in the Korn shell or POSIX shell

The Korn Shell, or POSIX Shell, lets you perform command substitution. In command substitution, the shell executes a specified command in a subshell environment and replaces that command with its output.

To execute command substitution in the Korn shell or POSIX shell, type the following:

text
$(command)

or, for the backquoted version, type the following:

text
`command`

Note: Although the backquote syntax is accepted by ksh, it is considered obsolete by the X/Open Portability Guide Issue 4 and POSIX standards. These standards recommend that portable applications use the $(command) syntax.

The shell expands the command substitution by executing command in a subshell environment and replacing the command substitution (the text of command plus the enclosing $( ) or backquotes) with the standard output of the command, removing sequences of one or more newline characters at the end of the substitution.

In the following example, the $( ) surrounding the command indicates that the output of the whoami command is substituted:

text
echo My name is: $(whoami)

You can perform the same command substitution with:

text
echo My name is: `whoami`

The output from both examples for user dee is:

text
My name is: dee

You can also substitute arithmetic expressions by enclosing them in ( ). For example, the command:

text
echo Each hour contains $((60 * 60)) seconds

produces the following result:

text
Each hour contains 3600 seconds

The Korn shell or POSIX shell removes all trailing newline characters when performing command substitution. For example, if your current directory contains the file1, file2, and file3 files, the command:

text
echo $(ls)

removes the newline characters and produces the following output:

text
file1 file2 file3

To preserve newline characters, insert the substituted command in " ":

text
echo "$(ls)"

Arithmetic evaluation in the Korn shell or POSIX shell

The Korn shell or POSIX shell regular built-in let command enables you to perform integer arithmetic.

Constants are of the form [Base]Number. The Base parameter is a decimal number between 2 and 36 inclusive, representing the arithmetic base. The Number parameter is a number in that base. If you omit the Base parameter, the shell uses a base of 10.

Arithmetic expressions use the same syntax, precedence, and associativity of expression as the C programming language. All of the integral operators, other than double plus (++), double hyphen (—), question mark-colon (?: ), and comma (,), are supported. The following table lists valid Korn shell or POSIX shell operators in decreasing order of precedence:

  • - — Unary minus
  • ! — Logical negation
  • ~ — Bitwise negation
  • * — Multiplication
  • / — Division
  • % — Remainder
  • + — Addition
  • - — Subtraction
  • <<, >> — Left shift, right shift
  • <=,>=, <>, ==, != — Comparison
  • & — Bitwise AND
  • ^ — Bitwise exclusive OR Bitwise OR
  • && — Logical AND
  • || — Logical OR
  • = *=, /=, &= +=, -=, <<=, > >=, &=, ^=, |= — Assignment

Many arithmetic operators, such as *, &, <, and >, have special meaning to the Korn shell or POSIX shell. These characters must be quoted. For example, to multiply the current value of y by 5 and reassign the new value to y, use the expression:

text
let "y = y * 5"

Enclosing the expression in quotation marks removes the special meaning of the * character.

You can group operations inside let command expressions to force grouping. For example, in the expression:

text
let "z = q * (z - 10)"

the command multiplies q by the reduced value of z.

The Korn shell or POSIX shell includes an alternative form of the let command if only a single expression is to be evaluated. The shell treats commands enclosed in (( )) as quoted expressions. Therefore, the expression:

text
((x = x / 3))

is equivalent to:

text
let "x = x / 3"

Named parameters are referenced by name within an arithmetic expression without using the parameter substitution syntax. When a named parameter is referenced, its value is evaluated as an arithmetic expression.

Specify an internal integer representation of a named parameter with the -i flag of the typeset special built-in command. Using the -i flag, arithmetic evaluation is performed on the value of each assignment to a named parameter. If you do not specify an arithmetic base, the first assignment to the parameter determines the arithmetic base. This base is used when parameter substitution occurs.

Related concepts

Korn shell or POSIX shell commands The Korn shell is an interactive command interpreter and command programming language. It conforms to the Portable Operating System Interface for Computer Environments (POSIX), an international standard for operating systems. Parameters in the Korn shell Korn shell parameters are discussed below.

Field splitting in the Korn shell or POSIX shell

After performing command substitution, the Korn shell scans the results of substitutions for those field separator characters found in the IFS (Internal Field Separator) variable. Where such characters are found, the shell splits the substitutions into distinct arguments.

The shell retains explicit null arguments ("" or ’’) and removes implicit null arguments (those resulting from parameters that have no values).

  • If the value of IFS is a space, tab, or newline character, or if it is not set, any sequence of space, tab, or newline characters at the beginning or end of the input will be ignored and any sequence of those characters within the input will delimit a field. For example, the following input yields two fields,

school and days

text
<newline><space><tab>school<tab><tab>days<space>
  • Otherwise, and if the value of IFS is not null, the following rules apply in sequence. IFS white space is used to mean any sequence (zero or more instances) of white-space characters that are in the IFS value (for example, if IFS contains space/comma/tab, any sequence of space and tab characters is considered IFS white space).
  1. IFS white space is ignored at the beginning and end of the input.

  2. Each occurrence in the input of an IFS character that is not IFS white space, along with any adjacent IFS white space, delimits a field.

  3. Nonzero length IFS white space delimits a field.

List of Korn shell or POSIX shell special built-in commands:

Special commands are built into the Korn shell and POSIX shell and executed in the shell process.

  • : (colon) — Expands only arguments.
  • . (dot) — Reads a specified file and then executes the commands.
  • break — Exits from the enclosing for, while, until, or select loop, if one exists.
  • continue — Resumes the next iteration of the enclosing for, while, until, or select loop.
  • eval — Reads the arguments as input to the shell and executes the resulting command or commands.
  • exec — Executes the command specified by the Argument parameter, instead of this shell, without creating a new process.
  • exit — Exits the shell whose exit status is specified by the n parameter.
  • export — Marks names for automatic export to the environment of subsequently executed commands.
  • newgrp — Equivalent to the exec/usr/bin/newgrp [Group ...] command.
  • readonly — Marks the specified names read-only.
  • return — Causes a shell to return to the invoking script.
  • set — Unless options or arguments are specified, writes the names and values of all shell variables in the collation sequence of the current locale.
  • shift — Renames positional parameters.
  • times — Prints the accumulated user and system times for both the shell and the processes run from the shell.
  • trap — Runs a specified command when the shell receives a specified signal or signals.
  • typeset — Sets attributes and values for shell parameters.
  • unset — Unsets the values and attributes of the specified parameters.

Related concepts

Korn shell or POSIX shell built-in commands Special commands are built in to the Korn shell and POSIX shell and executed in the shell process.

Korn shell or POSIX shell regular built-in commands

The following is a list of the Korn shell or POSIX shell regular built-in commands.

  • alias — Prints a list of aliases to standard output.
  • bg — Puts specified jobs in the background.
  • cd — Changes the current directory to the specified directory or substitutes the current string with the specified string.
  • echo — Writes character strings to standard output.
  • fc — Selects a range of commands from the last HISTSIZE variable command typed at the terminal. Re-executes the specified command after old-to-new substitution is performed.
  • fg — Brings the specified job to the foreground.
  • getopts — Checks the Argument parameter for legal options.
  • jobs — Lists information for the specified jobs.
  • kill — Sends the TERM (terminate) signal to specified jobs or processes.
  • let — Evaluates specified arithmetic expressions.
  • print — Prints shell output.
  • pwd — Equivalent to the print -r -$PWD command.
  • read — Takes shell input.
  • ulimit — Sets or displays user process resource limits as defined in the /etc/security/limits file.
  • umask — Determines file permissions.
  • unalias — Removes the parameters in the list of names from the alias list.
  • wait — Waits for the specified job and terminates.
  • whence — Indicates how each specified name would be interpreted if used as a command name.

For more information, see Korn shell or POSIX shell built-in commands.

Related concepts

Korn shell or POSIX shell built-in commands Special commands are built in to the Korn shell and POSIX shell and executed in the shell process.

Conditional expressions for the Korn shell or POSIX shell

A conditional expression is used with the [[ compound command to test attributes of files and to compare strings.

Word splitting and file name substitution are not performed on words appearing between [[ and ]]. Each expression is constructed from one or more of the following unary or binary expressions:

  • -a File — True, if the specified file is a symbolic link that points to another file that does exist.
  • -b File — True, if the specified file exists and is a block special file.
  • -c File — True, if the specified file exists and is a character special file.
  • -d File — True, if the specified file exists and is a directory.
  • -e File — True, if the specified file exists.
  • -f File — True, if the specified file exists and is an ordinary file.
  • -g File — True, if the specified file exists and its setgid bit is set.
  • -h File — True, if the specified file exists and is a symbolic link.
  • -k File — True, if the specified file exists and its sticky bit is set.
  • -n String — True, if the length of the specified string is nonzero.
  • -o Option — True, if the specified option is on.
  • -p File — True, if the specified file exists and is a FIFO special file or a pipe.
  • -r File — True, if the specified file exists and is readable by the current process.
  • -s File — True, if the specified file exists and has a size greater than 0.
  • -t FileDescriptor — True, if specified file descriptor number is open and associated with a terminal device.
  • -u File — True, if the specified file exists and its setuid bit is set.
  • -w File — True, if the specified file exists and the write bit is on. However, the file will not be writable on a read-only file system even if this test indicates true.
  • -x File — True, if the specified file exists and the execute flag is on. If the specified file exists and is a directory, then the current process has permission to search in the directory.
  • -z String — True, if length of the specified string is 0.
  • -L File — True, if the specified file exists and is a symbolic link.
  • -O File — True, if the specified file exists and is owned by the effective user ID of this process.
  • -G File — True, if the specified file exists and its group matches the effective group ID of this process.
  • -S File — True, if the specified file exists and is a socket.
  • File1 -nt File2 — True, if File1 exists and is newer than File2.
  • File1 -ot File2 — True, if File1 exists and is older than File2.
  • File1 -ef File2 — True, if File1 and File2 exist and refer to the same file.
  • String1 = String2 — True, if String1 is equal to String2.
  • String1 != String2 — True, if String1 is not equal to String2.
  • String = Pattern — True, if the specified string matches the specified pattern.
  • String != Pattern — True, if the specified string does not match the specified pattern.
  • String1 < String2 — True, if String1 comes before String2 based on the ASCII value of their characters.
  • String1 > String2 — True, if String1 comes after String2 based on the ASCII value of their characters.
  • Expression1 -eq Expression2 — True, if Expression1 is equal to Expression2.
  • Expression1 -ne Expression2 — True, if Expression1 is not equal to Expression2.
  • Expression1 -lt Expression2 — True, if Expression1 is less than Expression2.
  • Expression1 -gt Expression2 — True, if Expression1 is greater than Expression2.
  • Expression1 -le Expression2 — True, if Expression1 is less than or equal to Expression2.
  • Expression1 -ge Expression2 — True, if Expression1 is greater than or equal to Expression2.
  • Note: In each of the previous expressions, if the File variable is similar to /dev/fd/n, where n is an

integer, then the test is applied to the open file whose descriptor number is n.

You can construct a compound expression from these primitives, or smaller parts, by using any of the following expressions, listed in decreasing order of precedence:

  • (Expression) — True, if the specified expression is true. Used to group expressions.
  • ! Expression — True, if the specified expression is false.
  • Expression1 && Expression2 — True, if Expression1 and Expression2 are both true.
  • Expression1 || Expression2 — True, if either Expression1 or Expression2 is true.

Quotation of characters in the Korn shell or POSIX shell

When you want the Korn shell or POSIX shell to read a character as a regular character, rather than with any normally associated meaning, you must quote it.

Each metacharacter has a special meaning to the shell and, unless quoted, causes termination of a word. The following characters are considered metacharacters by the Korn shell or POSIX shell and must be quoted if they are to represent themselves:

  • pipe (|)

  • ampersand (&)

  • semicolon (;)

  • less-than sign (<) and greater-than sign (>)

  • left parenthesis (() and right parenthesis ())

  • dollar sign ($)

  • backquote (') and single quotation mark (’)

  • backslash (\)

  • double-quotation marks (")

  • newline character

  • space character

  • tab character

To negate the special meaning of a metacharacter, use one of the quoting mechanisms in the following list.

  • Backslash — A backslash (\) that is not quoted preserves the literal value of the following character, with the exception of a newline character. If a newline character follows the backslash, then the shell interprets this as line continuation.
  • Single Quotation Marks — Enclosing characters in single quotation marks (’ ’) preserves the literal value of each character within the single quotation marks. A single quotation mark cannot occur within single quotation marks. A backslash cannot be used to escape a single quotation mark in a string that is set in single quotation marks. An embedded quotation mark can be created by writing, for example: 'a'\''b', which yields a’b.
  • Double Quotation Marks — Enclosing characters in double quotation marks (" ") preserves the literal value of all characters within the double quotation marks, with the exception of the dollar sign, backquote, and backslash characters, as follows: $ The dollar sign retains its special meaning introducing parameter expansion, a form of command substitution, and arithmetic expansion. The input characters within the quoted string that are also enclosed between $( and the matching ) will not be affected by the double quotation marks, but define that command whose output replaces the $(...) when the word is expanded. Within the string of characters from an enclosed ${ to the matching }, there must be an even number of unescaped double quotation marks or single quotation marks, if any. A preceding backslash character must be used to escape a literal { or }. ' The backquote retains its special meaning introducing the other form of command substitution. The portion of the quoted string, from the initial backquote and the characters up to the next backquote that is not preceded by a backslash, defines that command whose output replaces ' ... ' when the word is expanded. \ The backslash retains its special meaning as an escape character only when followed by one of the following characters: $, ', ", \, or a newline character.

A double quotation mark must be preceded by a backslash to be included within double quotation marks. When you use double quotation marks, if a backslash is immediately followed by a character that would be interpreted as having a special meaning, the backslash is deleted, and the subsequent character is taken literally. If a backslash does not precede a character that would have a special meaning, it is left in place unchanged, and the character immediately following it is also left unchanged. For example:

text
"\$"    ->      $
"\a"    ->      \a

The following conditions apply to metacharacters and quoting characters in the Korn or POSIX shell:

  • The meanings of dollar sign, asterisk ($*) and dollar sign, at symbol ($@) are identical when not quoted, when used as a parameter assignment value, or when used as a file name.

  • When used as a command argument, double quotation marks, dollar sign, asterisk, double quotation marks ("$*") is equivalent to "$1d$2d...", where d is the first character of the IFS parameter.

  • Double quotation marks, at symbol, asterisk, double quotation marks ("$@") are equivalent to "$1" "$2" ....

  • Inside backquotes (''), the backslash quotes the characters backslash (\), single quotation mark (’), and dollar sign ($). If the backquotes occur within double quotation marks (" "), the backslash also quotes the double quotation marks character.

  • Parameter and command substitution occurs inside double quotation marks (" ").

  • The special meaning of reserved words or aliases is removed by quoting any character of the reserved word. You cannot quote function names or built-in command names.