Home > Blockchain >  BASH Programming man
BASH Programming man

Time:09-21

I am writing program to find header files by function names. I have a file search.sh and for example ./search.sh calloc errno sqrt puts gives me

stdlib.h
errno.h
math.h
stdio.h

it is the correct answer. I was told that if the function was not found I need to output "*****". For example ./search.sh calloc foo_func should output

stdlib.h
*****

I ran into the following problem. Using a piece of code

x=$(man 3 $1)

when a function comes in that doesn't really exist before the code is processed

if [[$? ! = 0]];
then
  echo "*****"
  shift
  continue
fi

for ./search.sh calloc foo_func man himself prints the error message:

stdlib.h
There is no man page for foo_func in section 3
*****

I need the output:

stdlib.h
*****

CodePudding user response:

The error from man goes to the standard error. Redirect it to nowhere to get rid of it:

x=$(man 3 "$1" 2>/dev/null)
  • Related