[첫화면으로]Bash

마지막으로 [b]

자꾸 까먹는 것들 좀 적어두자.

1. 문자열 구분자

[Shell scripts 질문드립니다. | KLDP]

IFS=$'\n'

for LINE in `cat file`
do
echo ${LINE}
done

IFS 내부 변수는 기본적으로 "스페이스,탭,뉴라인"이기 때문에, 각 라인의 공백마다 다시 구분이 되어 버려서 LINE 변수에 한 단어씩 들어간다. 라인 별로 들어가게 하려면 구분자를 뉴라인만 쓰도록 설정해 줘야 함.

$'문자열'은 문자열 내에 \와 문자 또는 코드값을 써서 ANSI C 표준 이스케이프 문자로 치환한다.

              \a     alert (bell)
              \b     backspace
              \e     an escape character
              \f     form feed
              \n     new line
              \r     carriage return
              \t     horizontal tab
              \v     vertical tab
              \\     backslash
              \'     single quote
              \nnn   the eight-bit character whose value is the octal value nnn (one to three digits)
              \xHH   the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
              \cx    a control-x character

2. Login / Non-Login shell, Interactive / Non-interactive shell

3. Redirection

4. nullglob

* 등의 와일드카드에 매치되는 파일이 없을 때, 리터럴로 처리하지 않고 아예 제거함

# 빈 디렉토리에서 와일드카드 *는 리터럴 "*"로 처리됨
$ for file in *; do echo "[$file]"; done
[*]
$ shopt -s nullglob
$ for file in *; do echo "[$file]"; done
$   # 빈 목록을 얻는다

다만 이 옵션을 함부로 쓰는 것은 위험

$ shopt -s nullglob
# 만일 *.txt 에 매치되는 파일이 없다면, 아무것도 안 나오는 게 아니라 나머지 파일 전부가 출력될 것이다. (그냥 ls를 실행한 것과 동일)
$ ls *.txt
# *.txt 에 매치되는 파일이 없다면 표준 입력에서 grep을 시도하게 된다.
$ grep TEXT *.txt

5. Comments

https://mug896.github.io/bash-shell/index.html - Bash 스크립트 가이드

-- Raymundo 2020-4-3 7:25 pm
이름:  
Homepage:
내용:
 

컴퓨터분류

마지막 편집일: 2021-12-10 4:40 pm (변경사항 [d])
762 hits | Permalink | 변경내역 보기 [h] | 페이지 소스 보기