-
-
Save luistung/11371888 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/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