
readline_read_history 함수는 이전에 입력한 명령어를 읽어오는 함수로, readline 라이브러리의 함수 중 하나입니다. 이 함수는 readline의 history 파일에서 명령어를 읽어옵니다.
readline_read_history 함수는 다음과 같은 형식으로 읽어옵니다.
- 명령어는 한 줄씩 읽어옵니다.
- 읽어온 명령어는 NULL(NULL-terminated) 문자열로 저장됩니다.
- 읽어온 명령어는 readline의 history 목록에 추가됩니다.
이러한 형식으로 읽어온 명령어를 처리하는 방법은 다음과 같습니다.
- 읽어온 명령어를 사용하여 새로운 명령어를 입력할 수 있습니다.
- 읽어온 명령어를 수정하여 새로운 명령어를 입력할 수 있습니다.
- 읽어온 명령어를 삭제할 수 있습니다.
readline_read_history 함수를 사용하는 예제는 다음과 같습니다.
#hostingforum.kr
bash
#include
int main() {
char *line;
char **history = readline_read_history("/home/user/.bash_history");
while ((line = readline("> ")) != NULL) {
add_history(line);
// 명령어 처리 코드
}
free(history);
return 0;
}
이 예제에서는 readline_read_history 함수를 사용하여 ~/.bash_history 파일에서 명령어를 읽어옵니다. 읽어온 명령어는 readline의 history 목록에 추가됩니다. 사용자가 입력한 명령어는 readline 함수를 사용하여 처리됩니다.
2025-05-24 11:30