Problem with Input Parameters using Shell Script

i have this basic code that accepts for two input one for the source file and the other is for the target directory. basically it is a simple copy command. the problem is at the end of the execution the second parameter string was passed to first parameter and it displays a message like:

cp: archive: A file or directory in the path name does not exist.

this is what it looks like when code is run

$ sh archive_file_list.sh "/u02/app/ccalloc/dev/out/*.txt" "/export/home/ccalftd
v/data/archive"
current directory /u02/app/ccalloc/dev/out
copied EATVDAILY02132008.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY03292007.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY04082008.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY05012008.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY05282008.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY06052007.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY06062007.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY06192009.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY06222009.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY06242009.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY07132009.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY07142009.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY07152009.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY07162009.txt to /export/home/ccalftdv/data/archive
copied EATVDAILY10212009.txt to /export/home/ccalftdv/data/archive
copied PCARDDAILY07102009.txt to /export/home/ccalftdv/data/archive
copied citicc_pre_pack.txt to /export/home/ccalftdv/data/archive
copied archive to /export/home/ccalftdv/data/archive
cp: archive: A file or directory in the path name does not exist.

below is the actual code

pdir=`pwd`
p1=$1
p2=$2

# check for null parameter
if [ $# -lt 1 ] && [ $# -lt 2 ]; then
  echo "current directory $pdir"
  echo "required parameters for source and target directory is missing"
  echo "e.g. archive_file_list.sh /directory_source/filesource.dat /directory_target"
  echo "                          -------------------------------- -----------------"
  echo "                          ^                                ^"
  echo
else
  #check for directory entry only
  if [ -d $p1 ]; then
    pdir=$p1
    echo current directory $pdir
    cd $pdir
    ls -latr
    echo
  #check for directory entry and file
  elif [ -f $p1 ]; then
    pdir=`dirname $p1`
    echo current directory $pdir
    cd $pdir
    for f in $*
    do
      pfile=`basename $f`
      #ls -altr $pfile
      echo copied $pfile to "$p2"
      cp $pfile $p2
    done
  else
    echo $p1 not found
  fi
fi

# put a white space
echo

thanks,
warren

Does this happen each time?
I dont see how or why unless you had a faulty symbolic link blahblah.txt to archive somehow somewhere...

You use:

for f in $*
    do
      pfile=`basename $f`
      #ls -altr $pfile
      echo copied $pfile to "$p2"
      cp $pfile $p2
    done

Before your command $* consists of two fields:

$1="/u02/app/ccalloc/dev/out/*.txt"
-and- 
$2="/export/home/ccalftd"

By using referencing $* in the loop, $1 gets expanded to all those txt files, followed by $2 which gets expanded to /export/home/ccalftd as the last value.

so after you apply basename, first your script performs :

cp EATVDAILY02132008.txt ...
until 
cp citicc_pre_pack.txt ..

and then it tries to perform the last copy:

cp archive to /export/home/ccalftdv/data/archive

and of course /u02/app/ccalloc/dev/out/archive does not exist.

S.

Further to Scrutinizer.

Should be

for f in ${p1}

Note: The "for" statement will break for large numbers of files if the expanded "for" line exceeds the maximum length of a command allowed in your shell. It will also break if a filename contains space characters.
A while loop is preferred for long lists.