tags:

views:

24

answers:

2

As the title say. I need to be able to backup and then recover files.

To make the back up was pretty simple

 if [ "$bup" = "true" ]; then
     cp $file $file.bak

But to make the recovery.. was not as stright forward.

 elif [ "$rup" = "true" ]; then
     bak=`find /path/to/file/ | grep .bak`
     cp $bak ${bak/\.bak}
 fi

It works in bash but i need it to work in sh..

+1  A: 

The bash shell parameter expansion doesn't work in sh. Try this:

elif [ "$rup" = "true" ]; then
   bak=`find /path/to/file/ | grep .bak`
   orig=`echo $bak | sed 's/\.bak$//'`
   cp $bak $orig
fi

Don't forget to add a loop around that find output if you intend to process multiple .bak files.

Cakemox
Thanks! I used the extra variable as you proposed..
AlMehdi
A: 

Use substring processing instead of the regex variant:

orig=${bak%.bak}
wds