Study with Me!
Seongmo
Study with Me!
전체 방문자
오늘
어제
  • Computer (126)
    • Computer Science (61)
      • Data Structure (51)
      • Algorithm (6)
      • 선형대수 with C++ (4)
    • Arm Architecture (1)
      • Register (0)
      • Assembly Instruction (1)
    • Linux (30)
      • Linux Kernel (4)
      • 라이브러리 함수 구현하기 (0)
      • 쉘, 쉘 명령어 구현하기 (15)
      • Ubuntu (11)
    • AWS (3)
    • Baekjoon (18)
    • Tools (6)
      • Git & Github (5)
      • Vim (1)
    • 개발 환경 (7)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • STL

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Study with Me!

Seongmo

[쉘 구현하기] pwd 명령어 구현
Linux/쉘, 쉘 명령어 구현하기

[쉘 구현하기] pwd 명령어 구현

2023. 8. 8. 22:59

현재 작업 위치를 출력하는 pwd 명령어를 구현했다.

이 명령어는 자식 프로세스를 생성하지는 않았고, 헤더 파일에 저장돼 있는 execPath를 출력만 했다.

// SM_shell.c
#include "my_header.h"
...
void prompt() {
    char input[STR_MAX];
    int command;

    while (1) {
        printf("SM_shell > ");
        
        fgets(input, STR_MAX, stdin);
        input[strlen(input) - 1] = '\0';

        if (!strcmp(input, commandList[0])) { // exit
            fprintf(stdout, "* SM_shell exit... *\n");
            exit(0);
        } else if (!strcmp(input, commandList[1])) { // help
            command = CMD_HELP;
        } else if (!strcmp(input, commandList[2])) {
            printf("%s\n\n", execPath);
            continue;
        }
        ...
}

int main(int argc, char **argv) {
    ...
}

코드는 생략했지만 헤더 파일에 commandList에도 "pwd"를 추가했다.

 

위 코드는 아래 이미지를 클릭해 깃허브에서도 확인할 수 있다.

깃허브 이미지 링크

저작자표시 (새창열림)

'Linux > 쉘, 쉘 명령어 구현하기' 카테고리의 다른 글

[쉘 구현하기] execv() 사용을 위한 문자열 배열 만들기  (0) 2023.08.11
[쉘 구현하기] ls 명령어 터미널 크기에 최적화  (0) 2023.08.09
[쉘 구현하기] ls 명령어 구현  (0) 2023.08.09
[쉘 구현하기] help 명령어 구현  (0) 2023.08.08
[쉘 구현하기] 쉘 초기 형태  (0) 2023.08.08
    'Linux/쉘, 쉘 명령어 구현하기' 카테고리의 다른 글
    • [쉘 구현하기] ls 명령어 터미널 크기에 최적화
    • [쉘 구현하기] ls 명령어 구현
    • [쉘 구현하기] help 명령어 구현
    • [쉘 구현하기] 쉘 초기 형태
    Study with Me!
    Study with Me!
    Study with Me!

    티스토리툴바