|
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
|