Created
January 3, 2013 01:02
-
-
Save hanigamal/4439936 to your computer and use it in GitHub Desktop.
To extract the <name> part of the file name, provided the dot separates <name> from <date> you can use parameter substitution in this way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd /path/to/backup/directory | |
for file in *.tgz | |
do | |
name=${file%%[.]*} | |
echo $name | |
if [ $name = $current_backup_name ] | |
then | |
# do new backup here | |
# delete older one here | |
fi | |
done | |
where current_backup_name will be the name of the backup you are currently processing, against which you want to find an existing backup. The ${file%%[.]*} substitution, will strip the longest part of the variable "file" from the back end, matching the pattern .* (dot followed by any number of other characters). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment