Skip to content

Instantly share code, notes, and snippets.

@hanigamal
Created January 3, 2013 01:02
Show Gist options
  • Save hanigamal/4439936 to your computer and use it in GitHub Desktop.
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
#!/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