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