Skip to content

Instantly share code, notes, and snippets.

@mjf
Created January 21, 2015 08:28
Show Gist options
  • Save mjf/f01f598c0dfb38ac5a3d to your computer and use it in GitHub Desktop.
Save mjf/f01f598c0dfb38ac5a3d to your computer and use it in GitHub Desktop.
fswap - File swap
#! /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