Help with very simple Shell Script

Write a shell that receives as parameters two folder names. Copies the
second folder as subfolder into the first one. Only folders and files
with the '.txt' extension will be copied. Detect and avoid recursive copy.

This is what I have to do and I don't know where to start. In fact, I started actually by writing this:

#!/bin/bash

#Write a shell that receives as parameters two folder names. Copies the
#second folder as subfolder into the first one. Only folders and files
#with the .txt extension will be copied. Detect and avoid recursive copy!

if [ ! $# -eq 2 ]
then echo usage: shell.sh Folder name Folder name
     exit 1
fi
# Check if the first parameter is a directory name
if [ ! -d $1 ]
then echo $1 is not a folder\!
     exit 1
fi

# Check if the second parameter is a directory name
if [ ! -d $2 ]
then echo $2 is not a folder\!
     exit 1
fi

Now I have to actually solve the problem :confused:

Read your man page of cp.

I've read it, but I'm still stuck. I'm trying something like

for fis in `find $f2 -name '*.txt'`; do
echo $fis #use some copy command here instead, echo just for test
done

but I can't get rid of the recursive search and that is what I am supposed to avoid.

Not necessary to use the find command use ls to loop through the current directory:

for fis in *.txt

Could you write the whole script Franklin? I'm :wall:

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.