Write a function that prints all filenames in a specified directory hierarchy without using either ls or find. Its output should be similar to the output of the find command:

$ myfind /users/pat
/users/pat
/users/pat/bin
/users/pat/bin/ksh
/users/pat/bin/lf
/users/pat/bin/pic
/users/pat/chapt1
/users/pat/chapt1/intro
/users/pat/rje
/users/pat/rje/filel
(Hint: Bash and Korn shell functions can be recursive.)

#!/bin/sh

# myfind - recursively list all files and directories
# from the specified starting point


function listfiles
{
for name in $(echo $1/*)
do
echo $name
if [ -d "$name" ] ; then
listfiles "$name"
fi
done
}

if [ -z "$1" ] ; then
listfiles $(pwd)
else
listfiles "$1"
fi

exit 0

Computer Science & Information Technology

You might also like to view...

Changes to data are saved automatically, but can be undone while the table or form is open by using the Undo button

Indicate whether the statement is true or false

Computer Science & Information Technology

Fill in the blank with the correct response. The three __________ references were called before they were extended an interview.?

A. ?finalists B. ?finalist's C. ?finalists'

Computer Science & Information Technology