2013-03-02 4 views
3

"n"커맨드의 첫 번째 라인만을 제공하는 bash 스크립트를하려고합니다.커스텀 아웃풋을 가진 남자를위한 bash 스크립트

예 :

$ sh ./start.sh ls wazup top 
ls - list directory contents 
wazup - manpage does not exist 
top - display Linux tasks 

이 내 현재 코드입니다 :

! bin/bash/ 
while [ -n "$1" ] 
do 
which $1> /dev/null 
man $1 | head -6 | tail -1 
if [ $? = 0 ] 
then 
echo "manpage does not exist" 
fi 
shift 
done 

내 출력은 다음과 같습니다

ls - list directory contents 
manpage does not exist 
No manual entry for wazzup 
manpage does not exist 
top - display Linux processes 
manpage does not exist 
+0

0의 종료 상태 성공합니다 (C-스타일 부울 대회의 반대)을 나타냅니다 :

는 여기를 필요로 누군가를 위해 내 마지막 코드입니다. 0이 아닌 값은 실패를 나타냅니다. – chepner

답변

2

는이를 통해 파이프 것 아니하면, man에 의해 반환 된 상태 코드를 확인 headtail (i가 잘못 될 것입니다. t는 tail의 반환 상태가됩니다).

1

많은 감사 알렉스!

귀하의 도움으로 파이프를 사용하지 않음으로써 해결했습니다!

#!/bin/bash 
while [ -n "$1" ] 
do 
which $1> /dev/null 
if [ $? = 0 ] 
then 
man -f $1 
else 
echo "$1: manpage does not exist" 
fi 
shift 
done