Created
January 21, 2015 08:28
-
-
Save mjf/f01f598c0dfb38ac5a3d to your computer and use it in GitHub Desktop.
fswap - File swap
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/sh | |
# fswap - File swap | |
# Copyright (C) 2015 Matous Jan Fialka, <http://mjf.cz/> | |
# Released under the terms of "The MIT License" | |
if [ $# -ne 2 ] | |
then | |
echo "fswap FILE1 FILE2" >&2 | |
exit 1 | |
fi | |
set -f | |
if TEMP_FILE="$(mktemp /tmp/fswap-XXXXXXXXXXXXXXXX)" | |
then | |
if mv "$1" "$TEMP_FILE" | |
then | |
if mv "$2" "$1" | |
then | |
mv "$TEMP_FILE" "$2" | |
fi | |
fi | |
rm "$TEMP_FILE" | |
fi | |
# vi:ft=sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment