Register
It is currently Mon Oct 20, 2014 11:56 am

cp -r script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed Apr 13, 2011 6:20 am   

Joined: Wed Apr 13, 2011 6:01 am
Posts: 2
Dear all,

I need to implement recursive copying in a bash script due to a non-standard access to a local file system (cp does not work). I managed to implement the recursive function, but (as far as I can see) each time the function is called, the internal variables are staying the same. I mean if I call a function f() once and I set the variable b in the function to - 5 let's say, after I call the function f() from itself, and set the variable b to 3, returning back to the function the value of the variable b is.. 3! Here is the script I have:

function filecopy(){
if [ -d $1 ]; then
DirName=`basename $1`
cd $1
mkdir $2/$DirName
DirList=`ls -lh | sed '1d' | awk '{ print $9}'`

for Entry in $DirList
do
filecopy $1/$Entry $2/$DirName
done
else
cp $1 $2/
fi
}

filecopy $1 $2

The input of the script are directory tree which I want to copy ($1) to destination folder where I want to copy it ($2). Thank you in advance


Top
 Profile  
 PostPosted: Wed Apr 13, 2011 9:03 am   

Joined: Wed Apr 13, 2011 6:01 am
Posts: 2
Problem solved.. The easiest answer is that all variables should be local.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP