Created
June 21, 2018 23:04
-
-
Save Linda-chan/342a2b35ee32178d11e68982aa4f1479 to your computer and use it in GitHub Desktop.
This file contains 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 | |
SRC_FILE_NAME="$1" | |
if [[ "$SRC_FILE_NAME" = "" ]] ; then | |
echo "Usage: $0 FILE" | |
exit | |
fi | |
if [[ ! -f "$SRC_FILE_NAME" ]] ; then | |
echo "Not a regular file: $SRC_FILE_NAME" | |
exit | |
fi | |
for TMP in {00..99} | |
do | |
BAK_FILE_NAME="$SRC_FILE_NAME.bak$TMP" | |
if [[ ! -e "$BAK_FILE_NAME" ]] ; then | |
echo "Backing up file: $SRC_FILE_NAME ==> $BAK_FILE_NAME" | |
cp --preserve=all -- "$SRC_FILE_NAME" "$BAK_FILE_NAME" | |
if [[ "$?" == "0" ]] ; then | |
chmod -x -- "$BAK_FILE_NAME" | |
fi | |
exit | |
fi | |
done | |
echo "Can't find free file name: $SRC_FILE_NAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment