현재 작업 위치를 출력하는 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 |