Function below is for verbosely checking mv syntax. Note , that it only works for 2 arguments, SOURCE and DESTINATION, and doesn't check for -t flag.
The function is to be placed into ~/.bashrc . To use it immediately , open new terminal or run source ~/.bashrc
mv_check()
{
# Function for checking syntax of mv command
# sort of verbose dry run
# NOTE !!! this doesn't support the -t flag
# maybe it will in future (?)
# check number of arguments
if [ $# -ne 2 ]; then
echo "<<< ERROR: must have 2 arguments , but $# given "
return 1
fi
# check if source item exist
if ! readlink -e "$1" > /dev/null
then
echo "<<< ERROR: " "$item" " doesn't exist"
return 1
fi
# check where file goes
if [ -d "$2" ]
then
echo "Moving " "$1" " into " "$2" " directory"
else
echo "Renaming " "$1" " to " "$2"
fi
}
Here's some test runs:
$> mv_check TEST_FILE1 bin/python
Moving TEST_FILE1 into bin/python directory
$> mv_check TEST_FILE1 TEST_FILE2
Renaming TEST_FILE1 to TEST_FILE2
$> mv_check TEST_FILE1 TEST_FILE 2
<<< ERROR: must have 2 arguments , but 3 given
$> mv_check TEST_FILE1 TEST_FILE\ 2
Renaming TEST_FILE1 to TEST_FILE 2
$> mv_check TEST_FILE1 "TEST_FILE 2"
Renaming TEST_FILE1 to TEST_FILE 2
$> mv_check TEST_FILE1
<<< ERROR: must have 2 arguments , but 1 given