Created
May 5, 2025 21:40
-
-
Save dmgolembiowski/041aa63eb518c6409f652a20d364f16c to your computer and use it in GitHub Desktop.
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 | |
# Path: /usr/bin/swap | |
function swap() { | |
if [ ! -f "$1" ] || [ ! -f "$2" ]; then return 1; fi | |
TMPFILE=/dev/shm/tmp.$$ | |
dd if="$1" of=$TMPFILE status=none bs=512K && \ | |
dd if="$2" of="$1" status=none bs=512K && \ | |
dd if=$TMPFILE of="$2" status=none bs=512K && \ | |
( \ | |
if [ $? -ne 1 ]; then true; else unlink $TMPFILE && unset $TMPFILE; return 1; fi; \ | |
) && \ | |
sync && \ | |
unlink $TMPFILE | |
unset TMPFILE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment