0

How to write a shell script named "backup.sh" which accepts one parameter, which would be a filename/directory.

Create a backup copy of that with the .bak appended to its name.Show message on success.

If the file/directory does not exist, show a proper message.

i did up to this point.please help me to figure this out

#!/bin/sh
#create_backup.sh
And add a .bak
bak="${backup.sh}.bak"
if [ "$#" -eq 0 ]
then 
        exit 1;
    echo "File Succesfully backuped"
fi
cp ${1} "${1}.back"
echo "File is not found "
exit 0
1
  • turn on shell debugging with set -vx and you'll see right away that shells are treating `bak="${backup.sh}.bak" as you think. Good luck. Commented Mar 31, 2013 at 19:30

1 Answer 1

1
#!/bin/bash -e
directory=$1
cp -r $directory $directory.bak
echo "Success"

obvious caveats with pathing/error codes/etc

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.