2022-04-13 Linux_IO_Redirection

IO Redirection – 생활코딩

IO Redirection – 생활코딩

pipeline

ps aux | grep nyancat
Code language: Bash (bash)

pipeline : command to command


IO Redirection

output

1> : stdout to file (1>에서 1 생략 가능)

2> : stderr to file

[unix_cmd] 1> result.txt 2> error.log
Code language: Bash (bash)

input

cat < hello.txt //(stdin)
Code language: JavaScript (javascript)
cat hello.txt //(command-line arguments : argv, argc)
Code language: JavaScript (javascript)

혼종

head -n1 < hello.txt 1> result.txt 2> error.log
Code language: CSS (css)

append

기본적으로 꺽쇠를 하나 사용하면 덮어쓴다.

ls -al > list.txt

cat list.txt

ls -al >> list.txt

cat list.txt
Code language: CSS (css)

append 즉 이어 쓰고 싶다면 꺽쇠 두 개를 써라


입출력 값이 여러 개일 때

mail [email@email.com](<mailto:email@email.com>) << hahaha
> hi
> my
> name
> is
> tired_i
> hahaha
Code language: CSS (css)

hahaha는 다음에 동일한 문자가 오면 입력을 끝낸다는 특수기호

굳이 hahaha일 필요는 없다.


UNIX PROCESS IO Stream

input

  • standard input (stdin)
  • command-line arguments (argv, argc)
  • environment variables (getenv)

output

  • standard output (stdout)
  • standard error (stderr)
  • exit status (return, exit)

argv, argc

command-line arguments의 argv, argv 보충 설명.


argc : argument count

  • int argc
  • 전달된 인자의 개수
  • 실행파일도 인자로 인식

예시
./test.exe hello hi 안녕
인자 개수는 4개
exe파일, hello, hi, 안녕 → 4개


argv  : argument vector

  • int *argv[]
  • 입력받은 인자의 포인터 값을 저장한 배열

참고 : https://qzqz.tistory.com/177

https://qzqz.tistory.com/177

댓글 남기기