Bash

wwiki
이동: 둘러보기, 검색

https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html

bash 명령어를 사용하면 bash를 사용할 수 있다.

기본쉘을 변경하려면

chsh -s /bin/bash

정의(용어)[편집 | 원본 편집]

POSIX[편집 | 원본 편집]

Bash는 주로 POSIX 1003.1에서(https://standards.ieee.org/ieee/1003.1/7700/) Shell과 Utilities부분과 관련이 있다.

blank[편집 | 원본 편집]

공백 또는 탭 문자

builtin[편집 | 원본 편집]

실행파일이 아니라 Shell 자체에 내장된 명령이다.

control operator[편집 | 원본 편집]

control function을 수행하는 토큰이다. newline이거나 ‘||’, ‘&&’, ‘&’, ‘;’, ‘;;’, ‘;&’, ‘;;&’, ‘|’, ‘|&’, ‘(’, or ‘)’ 이다.

exit status[편집 | 원본 편집]

명령이 caller에게 리턴한 값이다. 8bit이다. (최대값 255)

field[편집 | 원본 편집]

text의 unit이다. text는 shell expansions의 하나의 결과이다. 명령이 실행되었을 때 expansion 후에 resulting fields는 명령어 이름과 arguments로서 사용된다.

file name[편집 | 원본 편집]

파일을 식별하는데 사용하는 문자열이다.

job[편집 | 원본 편집]

동일한 프로세스 그룹에 있는 파이프라인과 파이프라인에서 파생된 모든 프로세스로 구성된 프로세스 집합

job control[편집 | 원본 편집]

사용자가 프로세스 실행을 선택적으로 중지(일시 중지) 및 다시 시작(재개)할 수 있는 메커니즘

metacharacter[편집 | 원본 편집]

따옴표가 아닌 문자로 단어와 구분된다. metacharacter는 space, tab, newline 또는 다음 문자 중 하나이다. '|', '&', ';', '(', ')', '<', 또는 '>'.

name[편집 | 원본 편집]

letters, numbers, underscores로만 이루어진 단어이다. letter나 underscore로 시작한다. name은 쉘 변수와 함수명으로 사용된다. 식별자로 사용되기도 한다.

operator[편집 | 원본 편집]

control operator 혹은 redirection operator이다.

process group[편집 | 원본 편집]

같은 process group ID를 가지는 연관된 프로세스들의 묶음이다.

process group ID[편집 | 원본 편집]

reserved word[편집 | 원본 편집]

예약어. for, while 같은 것들이다.

return status[편집 | 원본 편집]

exit status와 같다.

signal[편집 | 원본 편집]

시스템에서 발생하는 이벤트를 커널이 프로세스에 알릴 수 있는 메커니즘입니다.

special builtin[편집 | 원본 편집]

POSIX에 의해 특별 분류된 builtin command.

token[편집 | 원본 편집]

shell에서 single unit으로 간주되는 문자의 sequence이다. word 이거나 operator이다.

word[편집 | 원본 편집]

shell에서 unit으로 취급되는 문자의 sequence이다. 단어들은 따옴표가 없는 metacharacters를 포함할 수 없다.

Shell Syntax[편집 | 원본 편집]

Shell Commands[편집 | 원본 편집]

Reserved Words[편집 | 원본 편집]

Simple Commands[편집 | 원본 편집]

Pipelines[편집 | 원본 편집]

List of Commands[편집 | 원본 편집]

Compound Commands[편집 | 원본 편집]

Looping Constructs[편집 | 원본 편집]

Conditional Constructs[편집 | 원본 편집]

if

if [ -z "$1" ] && [ -z "$2" ]

then

  somecode1

elif [ "$1" = "run" ]; then

  somecode

else

  somecode2

fi

연산자

=

!=

-z string

True if the length of string is zero.

-n string

True if the length of string is non-zero.

Grouping Commands[편집 | 원본 편집]

Coprocesses[편집 | 원본 편집]

GNU Parallel[편집 | 원본 편집]

Shell Functions[편집 | 원본 편집]

Shell Parameters[편집 | 원본 편집]

Shell Expansions[편집 | 원본 편집]

Brace Expansion[편집 | 원본 편집]

Tilde Expansion[편집 | 원본 편집]

Shell Parameter Expansion[편집 | 원본 편집]

명령 대체(Command Substitution)[편집 | 원본 편집]

다음과 같이 사용한다.

$(command)

or

`command`

변수에 넣어 출력할 수 있다. 첫번째 라인은 띄어쓰기가 없다.

OUTPUT=$(ls -1)
echo "${OUTPUT}"

Arithmetic Expansion[편집 | 원본 편집]

Process Substitution[편집 | 원본 편집]

Word Splitting[편집 | 원본 편집]

Filename Expansion[편집 | 원본 편집]

Quote Removal[편집 | 원본 편집]

Redirections[편집 | 원본 편집]

Executing Commands[편집 | 원본 편집]

Shell Scripts[편집 | 원본 편집]

stdout없애기[편집 | 원본 편집]

>/dev/null

stderr없애기[편집 | 원본 편집]

2>/dev/null

문자열[편집 | 원본 편집]

': 작은 따옴표 안의 문자 그대로 사용

": 문자열 변수는 치환

\": "출력해야 하는 경우


단축키[편집 | 원본 편집]

이동[편집 | 원본 편집]

  • alt+b: 현재 단어의 시작으로 이동
  • alt+f: 현재 단어의 끝으로 이동

잘라내기[편집 | 원본 편집]

  • alt+d: 커서부터 오른쪽 단어 잘라내기
  • ctrl+w: 커서의 왼쪽 단어 잘라내기
  • ctrl+k: 커서부터 끝까지 잘라내기
  • ctrl+u: 처음부터 커서 앞까지 잘라내기

실행[편집 | 원본 편집]

  •  !!: 직전 명령어 실행
  •  !tail: 이전 명령어 중에 tail 로 시작했던 명령어 실행
  • ctrl+r: Recall the last command matching the characters you provide.

프롬프트[편집 | 원본 편집]

.bashrc에 PS!변수에 저장된다.

special characters: https://www.gnu.org/software/bash/manual/html_node/Controlling-the-Prompt.html#Controlling-the-Prompt

ANSI color: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

외부입력[편집 | 원본 편집]

http://www.gnu.org/software/bash/bash.html

매뉴얼: http://www.gnu.org/software/bash/manual/html_node/index.html