On 01/12/2011 12:07 PM, [email protected] wrote:
Hi,
I want a script which will output all the commands in linux starting with a particular letter and their one line description (which comes as the first line when doing man on that command).

#!/bin/bash

read -p 'Enter string to search for commands starting with: ' ch
echo
if [ -n "$ch" ]
then
  cmdlist=$(echo /bin/${ch}* /usr/bin/${ch}* /sbin/${ch}* /usr/sbin/${ch}*)
  tmpfile=$(mktemp /tmp/commandsearch.XXXXXXXX)
  exec 3>$tmpfile
  for cmd in $cmdlist
  do
    whatis $(echo $cmd | awk -F/ '{ print $NF; }') >&3 2>&3
    if [ $? -eq 0 ]
    then
      cat $tmpfile
    else
      echo -n > $tmpfile
    fi
  done
  exec 3>&-
fi

--
Regards,
Nilesh Govindarajan
Facebook: http://www.facebook.com/nilesh.gr
Twitter: http://twitter.com/nileshgr
Website: http://www.itech7.com
VPS Hosting: http://www.itech7.com/a/vps

--
l...@iitd - http://tinyurl.com/ycueutm

Reply via email to