Skip to content

Instantly share code, notes, and snippets.

@luistung
Created April 28, 2014 13:22
Show Gist options
  • Save luistung/11371888 to your computer and use it in GitHub Desktop.
Save luistung/11371888 to your computer and use it in GitHub Desktop.
交换两个文件
#!/bin/sh
if [[ $# != 2 && $# != 3 ]]
then
echo '需要至少两个参数' >&2
echo 'usage:'
echo "$(basename $0) file1 file2 tmpdir" >&2
exit 1
fi
FILENAME=$(date +%Y%m%d%H%M%S)_$$
tmpdir=/tmp
if [[ $# == 3 ]]
then
tmpdir=$3
fi
mv $1 $tmpdir/$FILENAME && mv $2 $1 && mv $tmpdir/$FILENAME $2 || exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment