Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey guys, I am learning UNIX shell script and we are using bash shell I need hel

ID: 672692 • Letter: H

Question

Hey guys, I am learning UNIX shell script and we are using bash shell

I need help for write this function in UNIX, I would be appreciate if anyone can help me with this.

Write a function called findit that uses find to search from the directory specified as the 1st argument on the command line and looks for the file specified as the 2nd argument on the command line. Redirect find's output to to the screen, redirect any errors to /dev/null and pipe output to less.

Before findit runs find, have it check that the 1st argument exists on the command line.

Use either test's string check for non-zero length. Or you can check that $# variable is greater than zero. $# is the number of arguments passed to a command or function.

If no argument, print an error message.

If 1st argument exists, then check that it represents a directory. If not, print an error message.

Otherwise, run the find.

Explanation / Answer

findit()
{
if [ $1 ]; then

if [ -d $1 ]; then

find $1 -name $2 -print 2> /dev/null
echo "File found."

else

echo "$1 is not a directory...";
  
fi
else

echo "Missing the directory to search from...";
  
fi
}