Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash script for man with custom output

Tags:

bash

manpage

I'm trying to do a bash script which gives me only the first line of man for "n" commands.

example:

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

This is my current code:

! 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

My Output is:

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
like image 510
UraniumSnake Avatar asked Sep 20 '26 13:09

UraniumSnake


1 Answers

Check the status code returned by man, not once it's piped through head and tail (which will be wrong as it will be the return status of tail).

like image 67
alex Avatar answered Sep 22 '26 08:09

alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!