본문 바로가기

Programming Skills/Shell3

[Shell] 리다이렉션(Redirection) 리다이렉션을 구현하기에 앞서 어떤 것인지 여기 에서 알아보자 리다이렉션 구현하기 1. input redirect file2 위 명령 식과 동일하다. 오른쪽 꺽쇠같은 경우엔 왼쪽에 1이 생략되어져 있다. 예제 첫번째 방법 #include #include int output_redirection() { close(STDOUT_FILENO); output_fd = open(file2, O_CREAT | O_WRONLY | O_TRUNC, 0644); if (output_fd < 0) return (ft_error_str(PERMISSION_ERR, file2)); re.. 2021. 5. 29.
[Shell] test([) 명령어 shell 의 test 유틸리티 설명 /bin/[ 에 위치해 있는 명령어이다. shell 의 if문(조건문) 구성을 할 때 필요로 한다. 예시 if [ 1000 -eq 2000 ]; then echo "same"; else echo "diff"; fi1000과 2000이 같다면 same을 다르다면 diff를 출력하라는 명령이다. 위와 같이 if문의 조건식을 판단할 때 사용한다. 2021. 5. 29.
[Unix] 파이프(pipe) 시스템 콜 - pipe() 없이 pipe 구현하기 1. man 2 pipe Prototype: int pipe(int fildes[2]); Description: 단방향 데이터 흐름을 만들어주는 파이프를 생성한다. 처음 fd는 read end에, 두번째 fd는 write end에 연결된다. 즉, filedes[1]에 데이터를 쓰면 filedes[0]에 나타난다. 이는 프로그램간의 데이터 통신을 구성할 수 있게 해준다. 이와 같이 STDOUT과 STDIN은 하나의 pipe로 연결되어 있다는 것을 알 수 있다. One of the most significant consequences of pipes in Unix is that Unix programs, whenever possible, are designed to read from standard inpu.. 2021. 5. 29.