Bash용 로드 가능한 내장 기능을 구축하는 방법

Bash용 로드 가능한 내장 기능을 구축하는 방법

최근에 배운 것처럼 사용자 정의 내장 기능을 Bash에 동적으로 로드하는 것이 가능합니다(참조enable설명서에, 그리고이 답변). 하지만 이 기능을 어떻게 활용해야 할지 잘 모르겠습니다.

연결된 질문은 다음을 가리킨다.https://mywiki.wooledge.org/BashLoadableBuiltins몇 가지 컴파일 지침을 제공하지만 Bash 5.0에서는 재현할 수 없습니다.

$ git clone https://git.savannah.gnu.org/git/bash.git
$ cd bash/
$ ./configure
$ make
$ exec ./bash
$ cd examples/loadables/
$ make
$ enable -f finfo finfo
bash: enable: cannot open shared object finfo: finfo: cannot open shared object file: No such file or directory

(이것은전체 출력혹시라도 도움이 된다면)

Run이 파일을 찾는 동안 파일을 생성하는 make것 같습니다 . 적절한 아티팩트를 생성하는 단계를 놓쳤습니까? 사용자 정의 내장 함수를 구축하는 더 쉽고 일반적인 방법이 있습니까?examples/loadables.oenable.so

답변1

파일 이름은 다음과 같아야 합니다."절대" 경로(이 경우 이는 슬래시가 있는 경로일 뿐입니다.) 또는 에서 검색 메커니즘 BASH_LOADABLES_PATH으로 돌아갑니다 (dlopen(3)예를 들어 Linux 맨페이지를 참조하세요.). 댓글에도 불구하고 그런 것 같습니다enable.def, 여기에는 현재 디렉터리가 포함되지 않습니다(IMO, 이는 좋은 것입니다).

다음 경로를 사용하세요.

bash-5.0$ enable -f print print
bash: enable: cannot open shared object print: print: cannot open shared object file: No such file or directory
bash-5.0$ enable -f ./print print
bash-5.0$ help print
print: print [-Rnprs] [-u unit] [-f format] [arguments]
    Display arguments.

    Output the arguments.  The -f option means to use the argument as a
    format string as would be supplied to printf(1).  The rest of the
    options are as in ksh.

관련 정보