
다 추출하려고 하는데명령 개요다음을 사용하는 맨페이지에서 /usr/share/man/man1
:
#!/usr/bin/env bash
## synopses - extract all synopses in /usr/share/man/man1
cd /usr/share/man/man1
for i in *.gz; do
echo "$i:" | sed -E "s/.1.gz|.gz//g"
man "./$i" | sed -n '/^SYNOPSIS/,/^[A-Z][A-Z][A-Z]/p' | sed -e '1d; $d' | tr -s [:space:]
done
...제공일부성공의 척도 - 다음에서 명령에 대한 완전한 출력을 얻습니다.ㅏ에게지. 하지만 나는 또한 많은 오류를 겪고 있습니다표준 오류for i in ./*.gz; do man "$i"
와 둘 다 사용for i in *.gz; do man "./$i"
파일로 출력할 때( synopses > file
) 1 :
<standard input>:27: expected `;' after scale-indicator (got `o')
<standard input>:29: expected `;' after scale-indicator (got `o')
<standard input>:283: name expected (got `\{'): treated as missing
<standard input>:674: warning: macro `as',' not defined (possibly missing space after `as')
<standard input>:174: name expected (got `\{'): treated as missing
<standard input>:161: warning [p 1, 5.5i]: can't break line
<standard input>:594: warning [p 5, 3.8i, div `an-div', 0.0i]: can't break line
<standard input>:569: warning [p 6, 0.0i]: can't break line
<standard input>:147: warning [p 1, 1.8i]: can't break line
<standard input>:205: warning [p 2, 0.2i]: can't break line
<standard input>:525: warning [p 5, 4.5i]: can't break line
<standard input>:157: warning [p 1, 4.8i]: can't break line
<standard input>:351: warning [p 3, 1.8i, div `an-div', 0.0i]: can't break line
<standard input>:147: a space character is not allowed in an escape name
man: can't open man1/zshmisc.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshexpn.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshparam.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshoptions.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshbuiltins.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshzle.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshcompwid.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshcompsys.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshcompctl.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshmodules.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshcalsys.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshtcpsys.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshzftpsys.1: No such file or directory
man: -:423: warning: failed .so request
man: can't open man1/zshcontrib.1: No such file or directory
man: -:423: warning: failed .so request
<standard input>:423: can't open `man1/zshmisc.1': No such file or directory
<standard input>:424: can't open `man1/zshexpn.1': No such file or directory
<standard input>:425: can't open `man1/zshparam.1': No such file or directory
<standard input>:426: can't open `man1/zshoptions.1': No such file or directory
<standard input>:427: can't open `man1/zshbuiltins.1': No such file or directory
<standard input>:428: can't open `man1/zshzle.1': No such file or directory
<standard input>:429: can't open `man1/zshcompwid.1': No such file or directory
<standard input>:430: can't open `man1/zshcompsys.1': No such file or directory
<standard input>:431: can't open `man1/zshcompctl.1': No such file or directory
<standard input>:432: can't open `man1/zshmodules.1': No such file or directory
<standard input>:433: can't open `man1/zshcalsys.1': No such file or directory
<standard input>:434: can't open `man1/zshtcpsys.1': No such file or directory
<standard input>:435: can't open `man1/zshzftpsys.1': No such file or directory
<standard input>:436: can't open `man1/zshcontrib.1': No such file or directory
이스케이프된 항목에 대한 오류 는 무엇 <standard input>
이며 man
일부 파일을 찾지 못하는 이유는 무엇입니까? 어떻게 하면 이를 더욱 강력하고 효율적으로 만들 수 있습니까?
1. 오류가 있는 것 같습니다.표준 오류동일한 데이터에 사용하는 구현/솔루션이 무엇이든 동일합니다. 그것은 놀랍습니다.
답변1
그냥 달리면 안 돼당신처럼 보입니다~할 수 있다실행 man foo.gz
man foo.1.gz
하지만 더 -l
깨끗해 보입니다. 에서 man man
:
-l, --local-file
Activate `local' mode. Format and display local manual files
instead of searching through the system's manual collection.
Each manual page argument will be interpreted as an nroff source
file in the correct format. No cat file is produced. If '-' is
listed as one of the arguments, input will be taken from stdin.
When this option is not used, and man fails to find the page
required, before displaying the error message, it attempts to
act as if this option was supplied, using the name as a filename
and looking for an exact match.
따라서 스크립트는 다음과 같아야 합니다.
#!/usr/bin/env bash
## synopses - extract all synopses in /usr/share/man/man1
## No need to cd into the directory, you can just use globs
for i in /usr/share/man/man1/ajc*.gz; do
## This will print the name of the command.
basename "${i//.1.gz}"
man -l "$i" |
awk '/^SYNOPSIS/{a=1; getline}
(/^[a-zA-z0-9_]/ && a==1){a=0}
(a==1 && /./){print}' | tr -s [:space:]
done
내가 제공하는 명령 awk
은 귀하의 접근 방식(예를 들어 테스트)보다 더 잘 작동하며 man ajc
이제 여러 줄 개요에서도 작동합니다. 표시되는 오류의 대부분은 관련이 없으며 다른 오류는 파일 이름을 처리하는 방식으로 인해 발생했습니다. 이것이 더 잘 작동하는지 알려주세요.
답변2
발생한 오류는 모두 여기에서 해결됩니다.
man man
MANWIDTH
-$MANWIDTH
이 설정되면 해당 값은 매뉴얼 페이지의 서식을 지정하는 줄 길이로 사용됩니다. 설정되지 않은 경우 매뉴얼 페이지는 현재 터미널에 적합한 행 길이로 형식화됩니다(사용 가능한 경우 ioctl(2) 값을 사용$COLUMNS
하거나 둘 다 사용할 수 없는 경우 80자로 대체). Cat 페이지는 기본 형식을 사용할 수 있는 경우, 즉 터미널 줄 길이가 66~80자 사이인 경우에만 저장됩니다.
MAN_KEEP_FORMATTING
- 일반적으로 출력이 터미널(예: 파일 또는 파이프)로 지정되지 않는 경우 특수 도구 없이 결과를 더 쉽게 읽을 수 있도록 서식 지정 문자가 삭제됩니다. 그러나$MAN_KEEP_FORMATTING
비어 있지 않은 값으로 설정되면 이러한 형식 지정 문자가 유지됩니다. 이는 서식 지정 문자를 해석할 수 있는 man 주위의 래퍼에 유용할 수 있습니다.
MAN_KEEP_STDERR
- 일반적으로 출력이 터미널(일반적으로 호출기)로 전달될 때 형식화된 매뉴얼 페이지 버전을 생성하는 데 사용된 명령의 오류 출력은 호출기 표시를 방해하지 않도록 삭제됩니다. 와 같은 프로그램은groff
잘못된 정렬과 같은 인쇄상의 문제에 대해 상대적으로 사소한 오류 메시지를 생성하는 경우가 많습니다. 이러한 오류 메시지는 매뉴얼 페이지와 함께 표시될 때 보기 흉하고 일반적으로 혼란스럽습니다. 그러나 일부 사용자는 어쨌든 이를 보고 싶어하므로$MAN_KEEP_STDERR
비어 있지 않은 값으로 설정하면 오류 출력이 평소대로 표시됩니다.
이제 다른 작업을 수행하는 방법에 대해 설명합니다.
나는 이것이 당신이 원하는 것을 한다고 생각합니다.
for f in /usr/share/man/man1/*gz ; do
man -P "sed -ne '1,/^[Nn]/d;/^ /{H;b}
/^[Ss]..[Yy]..[Nn]/{g;:n
N;/\n\(\n\)[^ ].*/!bn;s//\1/
s/.\x08//g;s/\(\n\) */\1/g;
w /dev/stderr' -ne '};/./q'" -l "$f"
done 2>~/file
이는 다음 라인만 출력 sed
하도록 지정합니다.PAGER
이름그리고 그 뒤를 따르는 사람들개요a 이외의 것으로 시작하는 다른 줄을 만날 때까지 <space>
. 인쇄합니다아무것도 아님<space>
그것 으로 시작하지 않는 첫 번째 줄이 다음과 같은 경우이름시작과 일치하지 않습니다 [Ss][Yy][Nn]
. 모든 경우에 다음과 같은 두 번째 줄에서 파일 읽기를 모두 종료합니다.이름로 시작하지 않는 것입니다 <space>
. 출력에서 선행 슬래시 <spaces>
와 모든 응답 슬래시를 지웁니다 .\b
for
방금 루프에서 실행했는데 man
단 1분 만에 내 전체 라이브러리에 걸쳐 루프가 실행되었습니다.
man
터미널에 쓰는지 파이프/파일에 쓰는지에 따라 출력을 조정합니다. 따라서 그렇게 하라고 지시하면 PAGER가 완전히 무시됩니다. 그것은 예상치 못한 일이었습니다. 그러나 나는 그것을 속이고 sed의 w
rite 함수를 사용하여 >&2에 기록하고 이를 리디렉션했기 때문에 더 이상 현명하지 못했습니다.
참고 사항 - 하지만 @terdon이 더 나은 방법일 수 있습니다. 파일당 하나 를 얻을 수 있기 때문에 이것을 더 쉽게 조정할 수 sed
있고 터미널 너비에 맞추려고 하지 않기 때문에 형식이 조금 더 좋지만 분명히 man
해당 \백슬래시를 |pipe
.