[AIX 운영 체제와 장치 관리 25] C 셸 (1) — 시작 파일, 제약, 별명·변수·파일 이름 치환, 문자 클래스, 환경 변수, 작업 제어, 내장 명령 목록, 신호 처리

핵심 정리

  • csh는 로그인할 때 /etc/csh.cshrc → /etc/csh.login → .cshrc → .login 순서로 읽습니다. .login 계열은 로그인 때 한 번, .cshrc 계열은 csh나 C 셸 스크립트를 호출할 때마다 실행되므로 내장 명령만 두는 것이 좋습니다.
  • 단어는 1024바이트, 인수 목록은 ARG_MAX, 한 줄의 별명 치환은 20번으로 제한되며 동치 클래스 파일 이름 펼치기는 지원하지 않습니다.
  • 변수는 단어 목록이며 $Name[n-m], $#Name, $?name, $<(표준 입력 한 줄)를 쓰고, :h, :t, :r, :q, :x 같은 수정자를 하나 붙일 수 있습니다.
  • ~, ~user, a{b,c,d}e는 파일 이름 줄임이고 *, ?, [ ]만 패턴 일치입니다. 맞는 패턴이 하나도 없으면 오류이며 nonomatch로 끌 수 있습니다.
  • argv, cwd, home, path, prompt, shell, status는 셸이 늘 설정하고, USER·TERM·HOME·PATH는 user·term·home·path로 복사됩니다. path는 .cshrc에서만 설정합니다.
항목 내용
버전 AIX 6.1 (5.3판과 거의 같음, 내장 명령 목록 추가)
원문 Operating system and device management — 5.3판 455474쪽, 6.1판 264274쪽
관련 명령어 csh, alias, unalias, set, unset, @, jobs, notify, rehash, onintr
관련 파일 /etc/csh.cshrc, /etc/csh.login, $HOME/.cshrc, $HOME/.login, ~/.history, .logout

C 셸은 대화식 명령 해석기이자 명령 프로그래밍 언어입니다. C 프로그래밍 언어와 비슷한 구문을 씁니다.

csh 명령이 C 셸을 시작합니다.

로그인하면 csh 명령은 먼저 시스템 전체 설정 파일 /etc/csh.cshrc를 찾습니다. 설정 파일이 있으면 C 셸은 그 파일에 저장된 명령을 실행합니다. 그다음 시스템 전체 설정 파일 /etc/csh.login이 있으면 실행합니다. 그런 다음 홈 디렉터리에서 .cshrc와 .login 파일을 찾습니다. 이 파일이 있으면 C 셸 실행에 관련된 사용자 맞춤 정보가 들어 있습니다. /etc/csh.cshrc와 /etc/csh.login 파일에서 설정한 모든 변수는 $HOME 디렉터리의 .cshrc와 .login 파일이 덮어쓸 수 있습니다. /etc/csh.cshrc와 /etc/csh.login 파일은 root 사용자만 고칠 수 있습니다.

/etc/csh.login과 $HOME/.login 파일은 로그인할 때 한 번만 실행됩니다. 이 파일에는 보통 환경 변수 정의, 로그인할 때 한 번 실행할 명령, 터미널 특성을 설정하는 명령을 둡니다.

/etc/csh.cshrc와 $HOME/.cshrc 파일은 로그인할 때와 csh 명령이나 C 셸 스크립트를 호출할 때마다 실행됩니다. 이 파일에는 보통 별명과 C 셸 변수(history, noclobber, ignoreeof 등) 같은 C 셸 특성을 정의합니다. 다른 명령을 쓰면 셸 스크립트 시작 시간이 늘어나므로 /etc/csh.cshrc와 $HOME/.cshrc 파일에는 C 셸 내장 명령만 쓰는 것이 좋습니다.

관련 참조

  • C 셸 내장 명령 목록

C 셸의 제약

C 셸에는 다음 제약이 있습니다.

  • 단어는 1024바이트보다 길 수 없습니다.
  • 인수 목록은 ARG_MAX 바이트로 제한됩니다. ARG_MAX 값은 /usr/include/sys/limits.h 파일에 있습니다.
  • 파일 이름 펼치기가 관련된 명령의 인수 수는 인수 목록에 허용된 바이트 수의 6분의 1로 제한됩니다.
  • 명령 치환은 인수 목록에 허용된 것보다 많은 바이트를 치환할 수 없습니다.
  • 반복을 감지하려고 셸은 한 줄의 별명 치환 수를 20으로 제한합니다.
  • csh 명령은 문자의 동치 분류에 기반한 파일 이름 펼치기를 지원하지 않습니다.
  • csh가 응용 프로그램을 실행하기 전에 연 파일 기술자(표준 입력, 표준 출력, 표준 오류 제외)는 그 응용 프로그램에서 쓸 수 없습니다.

C 셸의 별명 치환

별명은 명령이나 명령 문자열에 붙인 이름입니다. C 셸에서는 별명을 지정해 명령처럼 쓸 수 있습니다. 셸은 정의한 별명 목록을 유지합니다.

셸은 명령행을 훑은 뒤 명령을 서로 다른 단어로 나누고, 각 명령의 첫 단어를 왼쪽에서 오른쪽으로 확인해 별명인지 봅니다. 별명을 찾으면 기록 메커니즘으로 별명 텍스트를 별명이 가리키는 명령 텍스트로 바꿉니다. 결과 단어가 명령과 인수 목록을 대신합니다. 기록 목록을 참조하지 않으면 인수 목록은 바뀌지 않습니다.

alias와 unalias 내장 명령으로 별명 목록을 만들고 보여 주고 고칩니다. alias 명령은 다음 형식으로 씁니다.

text
alias [ Name [ WordList ]]

선택 Name 변수는 지정한 이름의 별명을 지정합니다. WordList로 단어 목록을 지정하면 그것을 Name의 별명으로 할당합니다. 두 선택 변수 없이 alias 명령을 실행하면 모든 C 셸 별명을 보여 줍니다.

ls 명령의 별명이 ls -l이면 다음 명령은

text
ls /usr

다음 명령으로 바뀝니다.

text
ls -l /usr

별명이 있는 명령에 기록 목록 참조가 없으므로 인수 목록은 바뀌지 않습니다. 마찬가지로 lookup 명령의 별명이 다음과 같으면

text
grep \!^ /etc/passwd

셸은 lookup bill을 다음으로 바꿉니다.

text
grep bill /etc/passwd

이 예에서 !^는 기록 목록을 가리키며, 셸은 이를 입력 줄의 첫 인수, 여기서는 bill로 바꿉니다.

별명에 특수 패턴 일치 문자를 쓸 수 있습니다. 다음 명령은

text
alias lprint ’pr &bslash2.!* >
> print’

인수를 줄 프린터용으로 서식화하는 명령을 만듭니다. 별명 안의 ! 문자는 작은따옴표로 셸에게서 보호되므로 pr 명령이 실행될 때까지 별명이 펼쳐지지 않습니다.

셸은 별명을 찾으면 입력 텍스트의 단어 변환을 하고, 다시 만든 입력 줄에서 별명 처리를 다시 시작합니다. 다음 텍스트의 첫 단어가 앞 텍스트와 같으면 별명에 표시를 붙여 별명 처리를 끝내 반복을 막습니다. 그 밖의 반복은 감지해 오류로 처리합니다.

관련 개념

  • C 셸의 기록 치환 — 기록 치환으로 이전 명령의 단어를 고쳐 새 명령을 만듭니다. 명령을 반복하거나, 이전 명령의 인수를 현재 명령에서 다시 쓰거나, 이전 명령의 철자 실수를 적은 입력으로 고칠 수 있습니다.

C 셸의 변수 치환

C 셸은 변수 집합을 유지하며, 각 변수의 값은 0개 이상의 단어 목록입니다. 이 가운데 일부는 셸이 설정하거나 참조합니다. 예를 들어 argv 변수는 셸 인수 목록의 상이며, 이 변수 값을 이루는 단어는 특별한 방법으로 참조합니다.

변수 값을 바꾸고 보려면 set과 unset 명령을 씁니다. 셸이 참조하는 변수 가운데 여럿은 토글(무언가를 켜고 끄는 변수)입니다. 셸은 토글의 값은 보지 않고 설정됐는지만 봅니다. 예를 들어 verbose 셸 변수는 명령 입력을 에코하게 하는 토글입니다. 명령행에서 -v 플래그를 주면 이 변수가 설정됩니다.

다른 연산은 변수를 숫자로 다룹니다. @ 명령은 숫자 계산을 하고 결과를 변수에 할당합니다. 그러나 변수 값은 늘 (0개 이상의) 문자열로 나타냅니다. 숫자 연산에서 빈 문자열은 0으로 보고, 여러 단어로 된 값의 둘째 이후 단어는 무시합니다.

명령을 내리면 셸은 입력 줄을 해석하고 별명 치환을 합니다. 그런 다음 명령을 실행하기 전에 변수 치환을 합니다. $ 문자가 치환을 이끕니다. 그러나 뒤에 공백, 탭, 줄 바꿈 문자가 오면 바뀌지 않고 그대로 넘어갑니다. $ 문자 앞에 \를 붙이면 펼치지 않지만, 두 가지 예외가 있습니다.

  • 명령을 " "로 감싼 경우. 이때 셸은 늘 치환합니다.
  • 명령을 ' '로 감싼 경우. 이때 셸은 절대 치환하지 않습니다. 역따옴표로 감싼 문자열은 명령 치환으로 해석합니다.

셸은 변수 펼치기 전에 입출력 방향 바꾸기를 인식해 따로 펼칩니다. 그 밖에는 명령 이름과 인수 목록 전체를 함께 펼칩니다. 그래서 첫 (명령) 단어가 여러 단어를 만들 수 있으며, 그 가운데 첫째가 명령 이름이 되고 나머지는 매개변수가 됩니다.

" "로 감싸거나 :q 수정자를 주지 않으면 변수 치환 결과는 결국 명령과 파일 이름 치환을 거칠 수 있습니다. 큰따옴표로 감싸면 여러 단어로 된 값의 변수는 단어 하나나 단어 하나의 일부로 펼쳐지며, 변수 값의 단어는 공백으로 구분됩니다. 치환에 :q 수정자를 적용하면 변수는 여러 단어로 펼쳐집니다. 각 단어는 공백으로 구분되고 이후 명령이나 파일 이름 치환을 막도록 큰따옴표로 감싸집니다.

다음 표기로 변수 값을 셸 입력에 넣을 수 있습니다. 따로 적지 않으면 set 명령으로 설정하지 않은 변수를 참조하면 오류입니다.

다음 치환에는 수정자 :gh, :gt, :gr, :h, :r, :q, :x를 적용할 수 있습니다. 명령 형식에 { }가 있으면 수정자는 중괄호 안에 둬야 합니다. 변수 펼치기마다 : 수정자는 하나만 쓸 수 있습니다.

  • $Name, ${Name} — Name 변수에 할당된 단어로 바뀌며 각 단어는 공백으로 구분됩니다. 중괄호는 Name을 뒤따르는 문자와 떼어 놓습니다. 셸 변수 이름은 문자로 시작하며 밑줄(_)을 포함한 문자와 숫자 20개까지로 이루어집니다. Name이 셸 변수가 아니지만 환경에 설정돼 있으면 그 값을 돌려줍니다. 이 경우 콜론이 붙은 수정자와 여기 설명한 다른 형식은 쓸 수 없습니다.
  • $Name[number], ${Name[number]} — Name 값의 단어 가운데 일부만 고릅니다. number는 변수 치환을 거치며, 숫자 하나나 하이픈(-)으로 구분한 숫자 둘일 수 있습니다. 변수 문자열 값의 첫 단어 번호는 1입니다. 범위의 첫 숫자를 생략하면 1, 마지막 숫자를 생략하면 $#Name이 기본값입니다. 별표(*)는 모든 단어를 고릅니다. 둘째 인수를 생략했거나 범위 안이면 범위가 비어도 오류가 아닙니다.
  • $#Name, ${#Name} — Name 변수의 단어 수입니다. 위처럼 [number] 안에 쓸 수 있습니다. 예: $Name[$#Name].
  • $0 — 명령 입력을 읽고 있는 파일의 이름으로 바뀝니다. 이름을 모르면 오류가 납니다.
  • $number, ${number} — $argv[number]와 같습니다.
  • $* — $argv[*]와 같습니다.

다음 치환은 : 수정자로 바꿀 수 없습니다.

  • $?name, ${?name} — name 변수가 설정돼 있으면 문자열 1, 아니면 0으로 바뀝니다.
  • $?0 — 현재 입력 파일 이름을 알면 1, 모르면 0으로 바뀝니다.
  • $$ — 부모 셸의 (십진) 프로세스 번호로 바뀝니다.
  • $< — 표준 입력의 한 줄로, 더 해석하지 않고 바뀝니다. 셸 프로시저에서 키보드로 읽을 때 씁니다.

관련 개념

  • C 셸의 명령 치환 — 명령 치환에서 셸은 지정한 명령을 실행하고 그 명령을 출력으로 바꿉니다.

C 셸의 파일 이름 치환

C 셸에서는 파일 이름 치환을 할 수 있습니다.

C 셸은 시간과 입력을 아끼는 지름길을 여러 개 제공합니다. 단어에 *, ?, [ ], { } 가운데 하나가 있거나 틸드(~)로 시작하면 그 단어는 파일 이름 치환 후보입니다. C 셸은 그 단어를 패턴으로 보고, 패턴과 맞는 파일 이름을 알파벳순으로 나열한 목록으로 바꿉니다.

LC_COLLATE나 LANG 환경 변수로 지정한 현재 정렬 순서를 씁니다. 파일 이름 치환을 지정한 단어 목록에서 어떤 패턴도 기존 파일 이름과 맞지 않으면 오류가 납니다. 그러나 모든 패턴이 맞을 필요는 없습니다. 패턴 일치나 파일 이름 펼치기를 나타내는 것은 문자 일치 기호 *, ?, [ ]뿐입니다. 틸드(~)와 { } 문자는 파일 이름 줄임을 나타냅니다.

C 셸의 파일 이름 펼치기

별표(*) 문자는 빈 문자열을 포함해 어떤 문자열과도 일치합니다.

예를 들어 다음 파일이 있는 디렉터리에서

text
a aa aax alice b bb c cc

echo a* 명령은 문자 a로 시작하는 모든 파일 이름을 출력합니다.

text
a aa aax alice

참고: 파일 이름을 맞출 때 점(.)과 슬래시(/) 문자는 명시적으로 맞춰야 합니다.

물음표(?) 문자는 아무 한 문자와 일치합니다. 다음 명령은

text
ls a?x

문자 a로 시작하고 한 문자가 오고 문자 x로 끝나는 모든 파일 이름을 나열합니다.

text
aax

한 문자나 문자 범위와 맞추려면 문자를 [ ] 안에 넣습니다. 다음 명령은

text
ls [abc]

감싼 문자 가운데 하나와 정확히 맞는 모든 파일 이름을 나열합니다.

text
a b c

대괄호 안에서 [a-z]는 사전순 문자 범위를 나타냅니다. 이 패턴과 맞는 문자는 현재 정렬 순서가 정합니다.

C 셸의 파일 이름 줄임

틸드(~)와 { 문자는 파일 이름 줄임을 나타냅니다. 파일 이름 처음의 ~는 홈 디렉터리를 나타냅니다. ~ 문자 하나만 있으면 home 셸 변수 값에 반영된 홈 디렉터리로 펼쳐집니다.

예를 들어 다음 명령은

text
ls ~

$HOME 디렉터리의 모든 파일과 디렉터리를 나열합니다.

~ 뒤에 문자, 숫자, 하이픈(-)으로 된 이름이 오면 셸은 그 이름의 사용자를 찾아 그 사용자의 $HOME 디렉터리로 바꿉니다.

참고: ~ 문자 뒤에 문자나 슬래시(/)가 아닌 문자가 오거나 단어 처음이 아닌 곳에 나오면 펼치지 않습니다.

파일 이름 전체를 입력하지 않고 파일 이름의 문자를 맞추려면 파일 이름에 { }를 씁니다. 패턴 a{b,c,d}e는 abe ace ade를 다르게 쓴 것입니다. 셸은 왼쪽에서 오른쪽 순서를 유지하며, 이 순서를 지키려고 일치 결과를 낮은 수준에서 따로 저장합니다. 이 구문은 중첩할 수 있습니다. 그래서 다음은

text
~source/s1/{oldls,ls}.c

source의 홈 디렉터리가 /usr/source이면 다음으로 펼쳐집니다.

text
/usr/source/s1/oldls.c /usr/source/s1/ls.c

마찬가지로 다음은

text
../{memo,*box}

다음으로 펼쳐질 수 있습니다.

text
../memo ../box ../mbox

참고: memo는 *box 일치 결과와 함께 정렬되지 않습니다. 특수한 경우로 {, }, { } 문자는 그대로 넘어갑니다.

C 셸의 문자 클래스

범위 표시 안에서 문자 클래스로 파일 이름을 맞출 수 있습니다.

다음 형식은 지정한 클래스에 속한 아무 한 문자와 일치시키라고 시스템에 지시합니다.

text
[: charclass :]

다음 클래스는 ctype 서브루틴과 대응합니다.

클래스 일치하는 문자
alnum 영숫자
alpha 대문자와 소문자
cntrl 제어 문자
digit 숫자
graph 그래픽 문자
lower 소문자
print 출력 가능한 문자
punct 구두점 문자
space 스페이스, 가로 탭, 캐리지 리턴, 줄 바꿈, 세로 탭, 폼 피드 문자
upper 대문자
xdigit 16진 숫자

다음 파일이 있는 디렉터리에 있다고 합시다.

text
a aa aax Alice b bb c cc

C 셸 프롬프트에서 다음 명령을 입력합니다.

text
ls [:lower:]

C 셸은 소문자로 시작하는 모든 파일 이름을 나열합니다.

text
a aa aax b bb c cc

문자 클래스 식에 관한 자세한 내용은 ed 명령을 봅니다.

C 셸의 환경 변수

어떤 변수는 C 셸에 특별한 뜻이 있습니다. 이 가운데 argv, cwd, home, path, prompt, shell, status는 셸이 늘 설정합니다.

cwd와 status 변수를 빼면 셸이 설정하는 것은 초기화 때뿐입니다. 위의 모든 변수는 명시적으로 다시 설정하지 않는 한 설정을 유지합니다.

csh 명령은 USER, TERM, HOME, PATH 환경 변수를 각각 csh 변수 user, term, home, path로 복사합니다. 일반 셸 변수를 다시 설정할 때마다 값이 환경으로 다시 복사됩니다. csh 하위 프로세스가 환경에서 path 정의를 가져오고 바뀌면 다시 내보내므로 path 변수는 .cshrc 파일 밖에서는 설정할 수 없습니다.

다음 변수에는 특별한 뜻이 있습니다.

변수 뜻
argv 셸 스크립트에 넘긴 인수. 위치 매개변수는 이 변수에서 치환합니다.
cdpath chdir이나 cd 명령이 하위 디렉터리를 찾을 다른 디렉터리 목록
cwd 현재 디렉터리의 전체 경로 이름
echo 명령행 플래그 -x를 쓰면 설정됩니다. 설정돼 있으면 각 명령과 인수를 실행 직전에 에코합니다. 내장이 아닌 명령은 모든 펼치기를 한 뒤 에코합니다. 내장 명령은 명령·파일 이름 치환을 선택적으로 하므로 그 전에 에코합니다.
histchars 기록 치환에 쓰는 문자를 바꾸는 문자열. 값의 첫 문자가 기본 기록 치환 문자 !를 대신하고, 둘째 문자가 빠른 치환의 ^를 대신합니다. 참고: 명령이나 파일 이름에 쓰는 문자로 설정하면 뜻하지 않은 기록 치환이 일어날 수 있습니다.
history 기록 목록 크기를 정하는 숫자. 허용한 이벤트 수 안에서 참조한 명령은 버리지 않습니다. 아주 큰 값은 셸 메모리를 바닥낼 수 있습니다. 설정 여부와 관계없이 C 셸은 늘 마지막으로 실행한 명령을 기록 목록에 저장합니다.
home 환경에서 초기화한 홈 디렉터리. 틸드(~) 문자의 파일 이름 펼치기가 이 변수를 가리킵니다.
ignoreeof 워크스테이션인 입력 장치에서 온 파일 끝 문자를 무시합니다. 셸이 파일 끝 문자(Ctrl-D)를 읽어 실수로 끝나는 것을 막습니다.
mail 셸이 메일을 확인할 파일. 명령이 끝나 프롬프트를 낼 때 지정한 시간 간격이 지났으면 확인합니다. 파일의 접근 시각이 변경 시각보다 이르면 Mail in file 메시지를 보여 줍니다. 값의 첫 단어가 숫자이면 다른 메일 확인 간격(초)을 지정하며 기본값은 600(10분)입니다. 메일 파일을 여럿 지정하면 그 파일에 메일이 있을 때 New mail in file 메시지를 보여 줍니다.
noclobber 출력 방향 바꾸기를 제한해 파일이 실수로 지워지지 않고 방향 바꾸기가 기존 파일에 덧붙도록 합니다.
noglob 파일 이름 펼치기를 막습니다. 파일 이름을 다루지 않는 셸 스크립트나, 파일 이름 목록을 얻은 뒤 더 펼치지 않으려 할 때 가장 쓸모 있습니다.
nonomatch 파일 이름 펼치기가 기존 파일과 하나도 맞지 않아도 오류를 내지 않고 원래 패턴을 돌려줍니다. 원래 패턴의 형식이 틀리면 여전히 오류입니다.
notify 작업 상태 변화를 비동기로 알립니다. 기본은 셸 프롬프트를 보여 주기 직전에 상태 변화를 보여 줍니다.
path 실행할 명령을 찾을 디렉터리. 빈 단어는 현재 디렉터리를 뜻합니다. path 변수가 설정돼 있지 않으면 전체 경로 이름만 실행할 수 있습니다. 기본 검색 경로(로그인 때 쓰는 /etc/environment 파일에서 옴)는 /usr/bin /etc /usr/sbin /usr/ucb /usr/bin/X11 /sbin입니다. -c나 -t 플래그 없이 시작한 셸은 보통 .cshrc를 읽은 뒤와 path 변수를 다시 설정할 때마다 path 디렉터리 내용을 해시합니다. 셸이 활성인 동안 이 디렉터리에 새 명령을 더하면 rehash 명령을 내려야 하며, 그러지 않으면 명령을 찾지 못할 수 있습니다.
prompt 대화식 워크스테이션 입력에서 각 명령을 읽기 전에 보여 주는 문자열. 문자열에 !가 있으면 현재 이벤트 번호로 바뀝니다. !가 작은따옴표나 큰따옴표로 감싼 문자열 안에 있으면 앞에 \\를 붙여야 합니다. root 권한이 없는 사용자의 기본 프롬프트는 %, root 권한 사용자는 #입니다.
savehist 로그아웃할 때 ~/.history 파일에 저장할 기록 목록 항목 수를 정하는 숫자. 이 이벤트 수 안에서 참조한 명령을 저장합니다. 시작할 때 셸은 ~/.history를 기록 목록으로 읽어 로그인 사이에 기록을 유지합니다. 아주 큰 값은 셸 시작을 느리게 합니다.
shell C 셸이 있는 파일. 실행 비트가 설정돼 있지만 시스템이 실행할 수 없는 파일을 해석하려고 셸을 fork할 때 씁니다. C 셸의 위치로 초기화됩니다.
status 마지막 명령이 돌려준 상태. 명령이 비정상 종료하면 상태에 0200을 더합니다. 실패한 내장 명령은 종료 상태 1을, 성공한 내장 명령은 0을 돌려줍니다.
time 명령의 자동 시간 측정을 제어합니다. 설정돼 있으면 지정한 CPU 초보다 오래 걸린 명령은 실행이 끝날 때 쓴 자원을 한 줄로 보여 줍니다. 기본 출력은 내장 time 명령을 봅니다.
verbose 명령행 플래그 -v로 설정되며, 기록 치환 뒤 각 명령의 단어를 보여 줍니다.

C 셸의 작업 제어

셸은 프로세스마다 작업 번호를 연결합니다. 셸은 현재 작업 표를 유지하며 작업에 작은 정수 번호를 매깁니다.

앰퍼샌드(&)로 백그라운드에서 작업을 시작하면 셸은 다음과 같은 줄을 출력합니다.

text
[1] 1234

이 줄은 작업 번호가 1이고 작업이 프로세스 ID 1234인 프로세스 하나로 이루어졌다는 뜻입니다. 현재 작업 표를 보려면 내장 jobs 명령을 씁니다.

백그라운드에서 실행 중인 작업이 워크스테이션에서 읽으려 하면 입력을 두고 다툽니다. 백그라운드 작업은 다른 작업의 출력과 뒤섞이는 출력을 워크스테이션에 낼 수도 있습니다.

셸에서 작업은 여러 방법으로 가리킬 수 있습니다. 퍼센트(%) 문자로 작업 이름을 시작합니다. 이 이름은 작업 번호이거나, 고유하다면 작업을 시작한 명령 이름일 수 있습니다. 예를 들어 make 프로세스가 작업 1로 실행 중이면 %1로 가리킬 수 있습니다. 이름이 문자열 make로 시작하는 일시 중단된 작업이 하나뿐이면 %make로도 가리킬 수 있습니다. 다음도 쓸 수 있습니다.

text
%?String

이름에 String이 든 작업이 하나뿐이면 그 작업을 지정합니다.

셸은 프로세스 상태가 바뀌면 바로 감지합니다. 작업이 막혀 더 진행할 수 없게 되면 셸은 워크스테이션에 메시지를 보냅니다. 이 메시지는 Enter 키를 누른 뒤에야 나옵니다. 그러나 notify 셸 변수가 설정돼 있으면 백그라운드 작업의 상태 변화를 바로 알립니다. 내장 notify 명령으로 프로세스 하나를 표시해 상태 변화가 바로 보고되게 합니다. 기본적으로 notify 명령은 현재 프로세스를 표시합니다.

C 셸 내장 명령 목록

다음은 C 셸 내장 명령입니다.

명령 설명
@ 지정한 셸 변수의 값을 보여 줍니다.
alias 지정한 별명이나 모든 별명을 보여 줍니다.
bg 현재 작업이나 지정한 작업을 백그라운드로 보냅니다.
break 가장 가까이 둘러싼 foreach나 while 명령의 end 뒤에서 실행을 이어갑니다.
breaksw switch 명령에서 빠져나갑니다.
case switch 명령의 레이블을 정의합니다.
cd 현재 디렉터리를 지정한 디렉터리로 바꿉니다.
chdir 현재 디렉터리를 지정한 디렉터리로 바꿉니다.
continue 가장 가까이 둘러싼 foreach나 while 명령의 실행을 계속합니다.
default switch 문의 기본 경우에 레이블을 붙입니다.
dirs 디렉터리 스택을 보여 줍니다.
echo 문자열을 셸의 표준 출력에 씁니다.
else if (Expression) then ... else if (Expression2) then ... else ... endif 명령 순서에서 둘째 else 뒤의 명령을 실행합니다.
end foreach 명령으로 시작한 명령 순서의 끝을 나타냅니다.
endif if (Expression) then ... else if (Expression2) then ... else ... endif 명령 순서의 끝을 나타냅니다(원문은 둘째 then 뒤의 명령을 실행한다고 적음).
endsw switch (String) case String : ... breaksw default: ... breaksw endsw 명령 순서의 끝을 나타냅니다. 이 순서는 각 case 레이블을 String 값과 차례로 맞춥니다. breaksw 명령을 실행하거나, 맞는 레이블이 없고 default도 없으면 endsw 명령 뒤에서 실행을 이어갑니다.
eval 변수 값을 셸 입력으로 읽고 결과 명령을 현재 셸 문맥에서 실행합니다.
exec 현재 셸 대신 지정한 명령을 실행합니다.
exit status 셸 변수 값이나 지정한 식의 값으로 셸을 끝냅니다.
fg 현재 작업이나 지정한 작업을 포그라운드로 가져오며, 멈춰 있으면 계속 실행합니다.
foreach end 명령에 이를 때까지 List의 각 구성원마다 Name 변수를 차례로 설정하고 명령 순서를 실행합니다.
glob 기록, 변수, 파일 이름 펼치기를 한 목록을 보여 줍니다.
goto 지정한 줄 뒤에서 실행을 이어갑니다.
hashstat 해시 표가 명령을 찾는 데 얼마나 성공했는지 보여 주는 통계를 보여 줍니다.
history 기록 이벤트 목록을 보여 줍니다.
if 지정한 식이 참이면 지정한 명령을 실행합니다.
jobs 활성 작업을 나열합니다.
kill 지정한 작업이나 프로세스에 TERM(종료) 신호나 Signal로 지정한 신호를 보냅니다.
limit 현재 프로세스와 그 프로세스가 만드는 각 프로세스의 지정한 자원 사용을 제한합니다.
login 로그인 셸을 끝내고 /usr/sbin/login 명령의 인스턴스로 바꿉니다.
logout 로그인 셸을 끝냅니다.
nice 셸에서 실행하는 명령의 우선순위를 설정합니다.
nohup 프로시저의 나머지 동안 hangup을 무시하게 합니다.
notify 현재 작업이나 지정한 작업의 상태가 바뀌면 셸이 비동기로 알리게 합니다.
onintr 인터럽트에 대한 셸의 동작을 제어합니다.
popd 디렉터리 스택을 꺼내고 새 맨 위 디렉터리로 돌아갑니다.
pushd 디렉터리 스택의 원소를 맞바꿉니다.
rehash path 셸 변수의 디렉터리 내용을 담은 내부 해시 표를 다시 계산하게 합니다.
repeat if 명령과 같은 제약 아래 지정한 명령을 지정한 횟수만큼 실행합니다.
set 모든 셸 변수의 값을 보여 줍니다.
setenv 지정한 환경 변수 값을 바꿉니다.
shift 지정한 변수를 왼쪽으로 옮깁니다.
source Name으로 지정한 파일의 명령을 읽습니다.
stop 백그라운드에서 실행 중인 현재 작업이나 지정한 작업을 멈춥니다.
suspend STOP 신호를 받은 것처럼 셸을 멈춥니다.
switch switch (String) case String : ... breaksw default: ... breaksw endsw 명령 순서를 시작합니다. 각 case 레이블을 String 값과 차례로 맞춥니다. default 레이블을 만나기 전까지 맞는 레이블이 없으면 default 레이블 뒤에서 실행을 시작합니다.
time 셸과 그 자식 프로세스가 쓴 시간 요약을 보여 줍니다.
umask 파일 권한을 정합니다.
unalias 이름이 Pattern과 맞는 별명을 모두 버립니다.
unhash 실행할 프로그램을 찾는 데 내부 해시 표를 쓰지 않게 합니다.
unlimit 자원 제한을 없앱니다.
unset 이름이 Pattern과 맞는 변수를 모두 지웁니다.
unsetenv 이름이 지정한 Pattern과 맞는 변수를 환경에서 모두 지웁니다.
wait 모든 백그라운드 작업을 기다립니다.
while Expression으로 지정한 식이 0이 아닌 동안 while과 짝이 맞는 end 사이의 명령을 평가합니다.

관련 정보는 다음과 같습니다.

  • Korn 셸 — ksh와 stty 명령. alias, cd, export, fc, getopts, read, set, typeset Korn 셸 명령. /etc/passwd 파일.
  • Bourne 셸 — bsh나 Rsh 명령, login 명령. Bourne 셸 read 특수 명령. setuid, setgid 서브루틴. null 특수 파일. environment 파일, profile 파일 형식.
  • C 셸 — csh 명령, ed 명령. alias, unalias, jobs, notify, set C 셸 내장 명령.

관련 개념

  • C 셸, C 셸 내장 명령 — 내장 명령은 셸 안에서 실행됩니다. 파이프라인의 마지막이 아닌 구성 요소로 나오면 서브셸에서 실행됩니다.

C 셸의 신호 처리

C 셸은 보통 quit 신호를 무시합니다. 분리해 실행 중인 작업은 키보드에서 만든 신호(INTERRUPT, QUIT, HANGUP)의 영향을 받지 않습니다.

다른 신호는 셸이 부모에게서 물려받은 값을 가집니다. 셸 프로시저에서 onintr로 INTERRUPT와 TERMINATE 신호에 대한 셸의 처리를 제어할 수 있습니다. 로그인 셸은 설정에 따라 TERMINATE 신호를 잡거나 무시합니다. 로그인 셸이 아닌 셸은 TERMINATE 신호를 자식 프로세스에 넘깁니다. 로그인 셸이 .logout 파일을 읽는 동안에는 어떤 경우에도 INTERRUPT 신호를 허용하지 않습니다.

영어 원문

C shell

The C shell is an interactive command interpreter and a command programming language. It uses syntax that is similar to the C programming language.

The csh command starts the C shell.

When you log in, the csh command first searches the system-wide setup file /etc/csh.cshrc. If the setup file exists, the C shell executes the commands stored in that file. Next, the C shell executes the system-wide setup file /etc/csh.login if it is available. Then, it searches your home directory for the .cshrc and .login files. If they exist, they contain any customized user information pertinent to running the C shell. All variables set in the /etc/csh.cshrc and /etc/csh.login files might be overridden by your .cshrc and .login files in your $HOME directory. Only the root user can modify the /etc/csh.cshrc and /etc/csh.login files.

The /etc/csh.login and $HOME/.login files are executed only once at login time. These files are generally used to hold environment variable definitions, commands that you want executed once at login, or commands that set up terminal characteristics.

The /etc/csh.cshrc and $HOME/.cshrc files are executed at login time and every time the csh command or a C shell script is invoked. They are generally used to define C shell characteristics, such as aliases and C shell variables (for example, history, noclobber, or ignoreeof). It is recommended that you only use the C shell built-in commands in the /etc/csh.cshrc and $HOME/.cshrc files because using other commands increases the startup time for shell scripts.

Related reference

C shell built-in commands list The following are C shell built-in commands.

C shell limitations

The following are limitations of the C shell.

  • Words can be no longer than 1024 bytes.

  • Argument lists are limited to ARG_MAX bytes. Values for the ARG_MAX variable are found in the /usr/include/sys/limits.h file.

  • The number of arguments to a command that involves file name expansion is limited to 1/6th the number of bytes allowed in an argument list.

  • Command substitutions can substitute no more bytes than are allowed in an argument list.

  • To detect looping, the shell restricts the number of alias substitutions on a single line to 20.

  • The csh command does not support file name expansion based on equivalence classification of characters.

  • File descriptors (other than standard in, standard out, and standard error) opened before csh executes any application are not available to that application.

Alias substitution in the C shell

An alias is a name assigned to a command or command string. The C shell allows you to assign aliases and use them as you would commands. The shell maintains a list of the aliases that you define.

After the shell scans the command line, it divides the commands into distinct words and checks the first word of each command, left to right, to see if there is an alias. If an alias is found, the shell uses the history mechanism to replace the text of the alias with the text of the command referenced by the alias. The resulting words replace the command and argument list. If no reference is made to the history list, the argument list is left unchanged.

The alias and unalias built-in commands establish, display, and modify the alias list. Use the alias command in the following format:

text
alias [ Name [ WordList ]]

The optional Name variable specifies the alias for the specified name. If you specify a word list with the WordList variable, the command assigns it as the alias of the Name variable. If you run the alias command without either optional variable, it displays all C shell aliases.

If the alias for the ls command is ls -l, the following command:

text
ls /usr

is replaced by the command:

text
ls -l /usr

The argument list is undisturbed because there is no reference to the history list in the command with an alias. Similarly, if the alias for the lookup command is as follows:

text
grep \!^ /etc/passwd

then the shell replaces lookup bill with the following:

text
grep bill /etc/passwd

In this example, !^ refers to the history list, and the shell replaces it with the first argument in the input line, in this case bill.

You can use special pattern-matching characters in an alias. The following command:

text
alias lprint ’pr &bslash2.!* >
> print’

creates a command that formats its arguments to the line printer. The ! character is protected from the shell in the alias by use of single quotation marks so that the alias is not expanded until the pr command runs.

If the shell locates an alias, it performs the word transformation of the input text and begins the alias process again on the reformed input line. If the first word of the next text is the same as the previous text, then looping is prevented by flagging the alias to terminate the alias process. Other subsequent loops are detected and result in an error.

Related concepts

History substitution in the C shell History substitution lets you modify individual words from previous commands to create new commands. History substitution makes it easy to repeat commands, repeat the arguments of a previous command in the current command, or fix spelling mistakes in the previous command with little typing.

Variable substitution in the C shell

The C shell maintains a set of variables, each of which has as its value a list of zero or more words. Some of these variables are set by the shell or referred to by it. For example, the argv variable is an image of the shell variable list, and words that comprise the value of this variable are referred to in special ways.

To change and display the values of variables, use the set and unset commands. Of the variables referred to by the shell, a number are toggles (variables that turn something on and off). The shell does not examine toggles for a value, only for whether they are set or unset. For example, the verbose shell variable is a toggle that causes command input to be echoed. The setting of this variable results from issuing the -v flag on the command line.

Other operations treat variables numerically. The @ command performs numeric calculations, and the result is assigned to a variable. Variable values are, however, always represented as (zero or more) strings. For numeric operations, the null string is considered to be zero, and the second and subsequent words of multi-word values are ignored.

When you issue a command, the shell parses the input line and performs alias substitution. Next, before running the command, it performs variable substitution. The $ character keys the substitution. It is,

however, passed unchanged if followed by a blank, tab, or newline character. Preceding the $ character with a \ prevents this expansion, except in two cases:

  • The command is enclosed in " ". In this case, the shell always performs the substitution.

  • The command is enclosed in ’ ’. In this case, the shell never performs the substitution. Strings enclosed in ' ' are interpreted for command substitution.

The shell recognizes input and output redirection before variable expansion and expands each separately. Otherwise, the command name and complete argument list expand together. It is therefore possible for the first (command) word to generate more than one word, the first of which becomes the command name, and the rest of which become parameters.

Unless enclosed in " " or given the :q modifier, the results of variable substitution might eventually be subject to command and file name substitution. When enclosed by double quotation marks, a variable with a value that consists of multiple words expands to a single word or a portion of a single word, with the words of the variable's value separated by blanks. When you apply the :q modifier to a substitution, the variable expands to multiple words. Each word is separated by a blank and enclosed in double quotation marks to prevent later command or file name substitution.

The following notations allow you to introduce variable values into the shell input. Except as noted, it is an error to reference a variable that is not set with the set command.

You can apply the modifiers :gh, :gt, :gr, :h, :r, :q, and :x to the following substitutions. If { } appear in the command form, then the modifiers must be placed within the braces. Only one : modifier is permitted on each variable expansion.

  • $Name
  • ${Name} — Replaced by the words assigned to the Name variable, each separated by a blank. Braces insulate the Name variable from any following characters that would otherwise be part of it. Shell variable names start with a letter and consist of up to 20 letters and digits, including the underline (_) character. If the Name variable does not specify a shell variable but is set in the environment, then its value is returned. The modifiers preceded by colons, as well as the other forms described here, are not available in this case.
  • $Name[number]
  • ${Name[number]} — Selects only some of the words from the value of the Name variable. The number is subjected to variable substitution and might consist of a single number or two numbers separated by a hyphen (-). The first word of a variable's string value is numbered 1. If the first number of a range is omitted, it defaults to 1. If the last number of a range is omitted, it defaults to $#Name. The asterisk (*) symbol selects all words. It is not an error for a range to be empty if the second argument is omitted or is in a range.
  • $#Name
  • ${#Name} — Gives the number of words in the Name variable. This can be used in a [number] as shown above. For example, $Name[$#Name].
  • $0 — Substitutes the name of the file from which command input is being read. An error occurs if the name is not known.
  • $number
  • ${number} — Equivalent to $argv[number].
  • $* — Equivalent to $argv[*].

The following substitutions may not be changed with : modifiers:

  • $?name
  • ${?name} — Substitutes the string 1 if the name variable is set, zero (0) if this variable is not set.
  • $?0 — Substitutes 1 if the current input file name is known, zero (0) if the file name is not known.
  • $$ — Substitutes the (decimal) process number of the parent shell.
  • $< — Substitutes a line from standard input, without further interpretation. Use this substitution to read from the keyboard in a shell procedure.

Related concepts

Command substitution in the C shell In command substitution, the shell executes a specified command and replaces that command with its output.

File name substitution in the C shell

The C Shell permits you to do file name substitutions.

The C shell provides several shortcuts to save time and keystrokes. If a word contains any of the characters *, ?, [ ], or { }, or begins with a tilde (~), that word is a candidate for file name substitution. The C shell regards the word as a pattern and replaces the word with an alphabetized list of file names matching the pattern.

The current collating sequence is used, as specified by the LC_COLLATE or LANG environment variables. In a list of words specifying file name substitution, an error results if no patterns match an existing file name. However, it is not required that every pattern match. Only the character-matching symbols *, ?, and [ ] indicate pattern-matching or file name expansion. The tilde (~) and { } characters indicate file name abbreviation.

File name expansion in the C shell

The asterisk (*) character matches any string of characters, including the null string.

For example, in a directory containing the files:

text
a aa aax alice b bb c cc

the command echo a* prints all files names beginning with the character a:

text
a aa aax alice

Note: When file names are matched, the characters dot (.) and slash (/) must be matched explicitly.

The question mark (?) character matches any single character. The following command:

text
ls a?x

lists every file name beginning with the letter a, followed by a single character, and ending with the letter x:

text
aax

To match a single character or a range of characters, enclose the character or characters inside of [ ]. The following command:

text
ls [abc]

lists all file names exactly matching one of the enclosed characters:

text
a b c

Within brackets, a lexical range of characters is indicated by [a-z]. The characters matching this pattern are defined by the current collating sequence.

File name abbreviation in the C shell

The tilde (~) and { characters indicate file name abbreviation. A ~ at the beginning of a file name is used to represent home directories. Standing alone, the ~ character expands to your home directory as reflected in the value of the home shell variable.

For example, the following command:

text
ls ~

lists all files and directories located in your $HOME directory.

When the command is followed by a name consisting of letters, digits, and hyphen (-) characters, the shell searches for a user with that name and substitutes that user's $HOME directory.

Note: If the ~ character is followed by a character other than a letter or slash (/), or appears anywhere except at the beginning of a word, it does not expand.

To match characters in file names without typing the entire file name, use { } around the file names. The pattern a{b,c,d}e is another way of writing abe ace ade. The shell preserves the left-to-right order and separately stores the results of matches at a low level to preserve this order. This construct might be nested. Thus, the following:

text
~source/s1/{oldls,ls}.c

expands to:

text
/usr/source/s1/oldls.c /usr/source/s1/ls.c

if the home directory for source is /usr/source. Similarly, the following:

text
../{memo,*box}

might expand to:

text
../memo ../box ../mbox

Note: memo is not sorted with the results of matching *box. As a special case, the {, }, and { } characters are passed undisturbed.

Character classes in the C shell

You can use character classes to match file names within a range indication.

The following format instructs the system to match any single character belonging to the specified class:

text
[: charclass :]

The following classes correspond to ctype subroutines:

  • alnum — Alphanumeric characters
  • alpha — Uppercase and lowercase letters
  • cntrl — Control characters
  • digit — Digits
  • graph — Graphic characters
  • lower — Lowercase letters
  • print — Printable characters
  • punct — Punctuation character
  • space — Space, horizontal tab, carriage return, newline, vertical tab, or form-feed character
  • upper — Uppercase characters
  • xdigit — Hexadecimal digits

Suppose that you are in a directory containing the following files:

text
a aa aax Alice b bb c cc

Type the following command at a C shell prompt:

text
ls [:lower:]

The C shell lists all file names that begin with lowercase characters:

text
a aa aax b bb c cc

For more information about character class expressions, see the ed command.

Environment variables in the C shell

Certain variables have special meaning to the C shell. Of these, argv, cwd, home, path, prompt, shell, and status are always set by the shell.

Except for the cwd and status variables, the action of being set by the shell occurs only at initialization. All of the above variables maintain their settings unless you explicitly reset them.

The csh command copies the USER, TERM, HOME, and PATH environment variables into the csh variables, user, term, home, and path, respectively. The values are copied back into the environment whenever the normal shell variables are reset. The path variable cannot be set in other than in the .cshrc file because csh subprocesses import the path definition from the environment and reexport it if changed.

The following variables have special meanings:

  • argv — Contains the arguments passed to shell scripts. Positional parameters are substituted from this variable.
  • cdpath — Specifies a list of alternate directories to be searched by the chdir or cd command to find subdirectories.
  • cwd — Specifies the full path name of the current directory.
  • echo — Set when the -x command line flag is used; when set, causes each command and its arguments to echo just before being run. For commands that are not built-in, all expansions occur before echoing. Built-in commands are echoed before command and file name substitution because these substitutions are then done selectively.
  • histchars — Specifies a string value to change the characters used in history substitution. Use the first character of its value as the history substitution character, this replaces the default character, !. The second character of its value replaces the ^ character in quick substitutions. Note: Setting the histchars value to a character used in command or file names might cause unintentional history substitution.
  • history — Contains a numeric value to control the size of the history list. Any command that is referenced within the number of events permitted is not discarded. Very large values of the history variable might cause the shell to run out of memory. Regardless of whether this variable is set, the C shell always saves the last command that ran on the history list.
  • home — Indicates your home directory initialized from the environment. The file name expansion of the tilde (~) character refers to this variable.
  • ignoreeof — Specifies that the shell ignore an end-of-file character from input devices that are workstations. This prevents shells from accidentally being killed when the shell reads an end-of-file character (Ctrl-D).
  • mail — Specifies the files where the shell checks for mail. This is done after each command completion which results in a prompt if a specified time interval has elapsed. The shell displays the message Mail in file if the file exists with an access time less than its change time. If the first word of the value of the mail variable is numeric, it specifies a different mail-checking time interval (in seconds); the default is 600 (10 minutes). If you specify multiple mail files, the shell displays the message New mail in file, when there is mail in the specified file.
  • noclobber — Places restrictions on output redirection to ensure that files are not accidentally destroyed and that redirections append to existing files.
  • noglob — Inhibits file name expansion. This is most useful in shell scripts that do not deal with file names or when a list of file names has been obtained and further expansions are not desirable.
  • nonomatch — Specifies that no error results if a file name expansion does not match any existing files; rather, the primitive pattern returns. It is still an error for the primitive pattern to be malformed.
  • notify — Specifies that the shell send asynchronous notification of changes in job status. The default presents status changes just before displaying the shell prompt.
  • path — Specifies directories in which commands are sought for execution. A null word specifies the current directory. If there is no path variable set, then only full path names can run. The default search path (from the /etc/environment file used during login) is as follows: /usr/bin /etc /usr/sbin /usr/ucb /usr/bin/X11 /sbin A shell given neither the -c nor the -t flag normally hashes the contents of the directories in the path variable after reading the .cshrc and each time the path variable is reset. If new commands are added to these directories while the shell is active, you must give the rehash command. Otherwise, the commands might not be found.
  • prompt — Specifies the string displayed before each command is read from an interactive workstation input. If a ! appears in the string, it is replaced by the current event number. If the ! character is in a quoted string enclosed by single or double quotation marks, the ! character must be preceded by a \. The default prompt for users without root authority is % . The default prompt for the user with root authority is #.
  • savehist — Specifies a numeric value to control the number of entries of the history list that are saved in the ~/.history file when you log out. Any command referenced in this number of events is saved. During startup, the shell reads ~/.history into the history list, enabling history to be saved across logins. Very large values of the savehist variable slow down the shell startup.
  • shell — Specifies the file in which the C shell resides. This is used in forking shells to interpret files that have execute bits set, but which are not executable by the system. This is initialized to the home of the C shell.
  • status — Specifies the status returned by the last command. If the command ends abnormally, 0200 is added to the status. Built-in commands that are unsuccessful return an exit status of 1. Successful built-in commands set status to a value of 0.
  • time — Controls automatic timing of commands. If this variable is set, any command that takes more than the specified number of CPU seconds will display a line of resources used at the end of execution. For more information about the default outputs, see the built-in time command.
  • verbose — Set by the -v command line flag, this variable causes the words of each command to display after history substitution.

Job control in the C shell

The shell associates a job number with each process. The shell keeps a table of current jobs and assigns them small integer numbers.

When you start a job in the background with an ampersand (&) , the shell prints a line that looks like the following:

text
[1] 1234

This line indicates that the job number is 1 and that the job is composed of a single process with a process ID of 1234. Use the built-in jobs command to see the table of current jobs.

A job running in the background competes for input if it tries to read from the workstation. Background jobs can also produce output for the workstation that gets interleaved with the output of other jobs.

You can refer to jobs in the shell in several ways. Use the percent (%) character to introduce a job name. This name can be either the job number or the command name that started the job, if this name is unique. For example, if a make process is running as job 1, you can refer to it as %1. You can also refer to it as %make if there is only one suspended job with a name that begins with the string make. You can also use the following:

text
%?String

to specify a job whose name contains the String variable, if there is only one such job.

The shell detects immediately whenever a process changes its state. If a job becomes blocked so that further progress is impossible, the shell sends a message to the workstation. This message displays only after you press the Enter key. If, however, the notify shell variable is set, the shell immediately issues a message that indicates changes in the status of background jobs. Use the built-in notify command to mark a single process so that its status changes are promptly reported. By default, the notify command marks the current process.

C shell built-in commands list

The following are C shell built-in commands.

  • @ — Displays the value of specified shell variables.
  • alias — Displays specified aliases or all aliases.
  • bg — Puts the current or specified jobs into the background.
  • break — Resumes running after the end of the nearest enclosing foreach or while command.
  • breaksw — Breaks from a switch command.
  • case — Defines a label in a switch command.
  • cd — Changes the current directory to the specified directory.
  • chdir — Changes the current directory to the specified directory.
  • continue — Continues execution of the nearest enclosing foreach or while command.
  • default — Labels the default case in a switch statement.
  • dirs — Displays the directory stack.
  • echo — Writes character strings to the standard output of the shell.
  • else — Runs the commands that follow the second else in an if (Expression) then ...else if (Expression2) then ... else ... endif command sequence.
  • end — Signifies the end of a sequence of commands preceded by the foreach command.
  • endif — Runs the commands that follow the second then statement in an if (Expression) then ... else if (Expression2) then ... else ... endif command sequence.
  • endsw — Marks the end of a switch (String) case String : ... breaksw default: ... breaksw endsw command sequence. This command sequence successively matches each case label against the value of the String variable. Execution continues after the endsw command if a breaksw command is executed or if no label matches and there is no default.
  • eval — Reads variable values as input to the shell and executes the resulting command or commands in the context of the current shell.
  • exec — Runs the specified command in place of the current shell.
  • exit — Exits the shell with either the value of the status shell variable or the value of the specified expression.
  • fg — Brings the current or specified jobs into the foreground, continuing them if they are stopped.
  • foreach — Successively sets a Name variable for each member specified by the List variable and a sequence of commands, until reaching an end command.
  • glob — Displays list using history, variable, and file name expansion.
  • goto — Continues to run after a specified line.
  • hashstat — Displays statistics indicating how successful the hash table has been at locating commands.
  • history — Displays the history event list.
  • if — Runs a specified command if a specified expression is true.
  • jobs — Lists the active jobs.
  • kill — Sends either the TERM (terminate) signal or the signal specified by the Signal variable to the specified job or process.
  • limit — Limits usage of a specified resource by the current process and each process it creates.
  • login — Ends a login shell and replaces it with an instance of the /usr/sbin/login command.
  • logout — Ends a login shell.
  • nice — Sets the priority of commands run in the shell.
  • nohup — Causes hangups to be ignored for the remainder of a procedure.
  • notify — Causes the shell to notify you asynchronously when the status of the current or a specified job changes.
  • onintr — Controls the action of the shell on interrupts.
  • popd — Pops the directory stack and returns to the new top directory.
  • pushd — Exchanges elements of the directory stack.
  • rehash — Causes recomputation of the internal hash table containing the contents of the directories in the path shell variable.
  • repeat — Runs the specified command, subject to the same restrictions as the if command, the number of times specified.
  • set — Shows the value of all shell variables.
  • setenv — Modifies the value of the specified environment variable.
  • shift — Shifts the specified variable to the left.
  • source — Reads command specified by the Name variable.
  • stop — Stops the current or specified jobs running in the background.
  • suspend — Stops the shell as if a STOP signal has been received.
  • switch — Starts a switch (String) case String : ... breaksw default: ... breaksw endsw command sequence. This command sequence successively matches each case label against the value of the String variable. If none of the labels match before a default label is found, the execution begins after the default label.
  • time — Displays a summary of the time used by the shell and its child processes.
  • umask — Determines file permissions.
  • unalias — Discards all aliases with names that match the Pattern variable.
  • unhash — Disables the use of the internal hash table to locate running programs.
  • unlimit — Removes resource limitations.
  • unset — Removes all variables having names that match the Pattern variable.
  • unsetenv — Removes all variables from the environment whose names match the specified Pattern variable.
  • wait — Waits for all background jobs.
  • while — Evaluates the commands between the while and the matching end command sequence while an expression specified by the Expression variable evaluates nonzero.

The following is related information:

Korn shell

The ksh and stty commands. The alias, cd, export, fc, getopts, read, set, and typeset Korn shell commands.

The /etc/passwd file.

Bourne shell

The bsh or Rsh command, login command.

The Bourne shell read special command.

The setuid subroutine, setgid subroutine.

The null special file.

The environment file, profile file format.

C shell

The csh command, ed command.

The alias, unalias, jobs, notify and set C Shell built-in commands.

Related concepts

C shell The C shell is an interactive command interpreter and a command programming language. It uses syntax that is similar to the C programming language. “C shell built-in commands” Built-in commands are run within the shell. If a built-in command occurs as any component of a pipeline, except the last, the command runs in a subshell.

Signal handling in the C shell

The C shell normally ignores quit signals. Jobs running detached are not affected by signals generated from the keyboard (INTERRUPT, QUIT, and HANGUP).

Other signals have the values the shell inherits from its parent. You can control the shell's handling of INTERRUPT and TERMINATE signals in shell procedures with onintr. Login shells catch or ignore TERMINATE signals depending on how they are set up. Shells other than login shells pass TERMINATE signals on to the child processes. In no cases are INTERRUPT signals allowed when a login shell is reading the .logout file.