I'm new to shell scripting and I trying to write a script that:
- Prompts for a directory
- Loops through the directory
- If it find files it then backs them up using a function in the script
- Creates a backup
I just created a file called file.bak for all the files to be copied into if they were found.
#!/bin/bash
function backup()
{
cp"$name" >> file.bak
}
#Main Script
echo -n "Please enter a directory name: "
read name
directory="/home/shawn"
if [ -O "$name" ] || [ -G "$name" ]
then
backup
else
echo "$name has no files."
fi