First versions of the binaries and source file.
This commit is contained in:
parent
d2630d6e4f
commit
1dfda10ddc
11 changed files with 742 additions and 0 deletions
42
sw
Executable file
42
sw
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
# It just swaps two files
|
||||
'
|
||||
FILE1=$1
|
||||
FILE2=$2
|
||||
|
||||
function helpFn()
|
||||
{
|
||||
ERROR=$?
|
||||
if [[ $ERROR -gt 0 ]];
|
||||
then
|
||||
echo "$BINSELF error ($ERROR): "
|
||||
perl -E 'say $!=shift' $ERROR
|
||||
fi
|
||||
echo "Usage: $BINSELF <file1> <file2>"
|
||||
echo Swap two files in a filesystem.
|
||||
exit $ERROR
|
||||
}
|
||||
|
||||
if [[ $@ == *"--help"* ]];
|
||||
then
|
||||
helpFn
|
||||
fi
|
||||
|
||||
# We set a trap here, together with 'set -e' above,
|
||||
# this makes sure we exit gracefully if we have an
|
||||
# error in one of the ls or mv calls.
|
||||
trap helpFn ERR
|
||||
|
||||
# We want to swap two files
|
||||
# Easy, but let's be safe about it
|
||||
ls "$FILE1" >/dev/null
|
||||
ls "$FILE2" >/dev/null
|
||||
|
||||
# Files should exist, now we move
|
||||
mv "$FILE1" "$FILE1.sw"
|
||||
mv "$FILE2" "$FILE2.sw"
|
||||
|
||||
# We got our moved copies, now we simply rename
|
||||
mv "$FILE1.sw" "$FILE2"
|
||||
mv "$FILE2.sw" "$FILE1"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue