If you want to hand file names that contain space, you need to double quote the paramters.
#!/bin/bash
# This is copy a file and appending the date and time to the end of the file.
# Not the following format is wrong, because you can't add the space between the
# varible name and = symbol.
#date_formatted =$(date +%m_%d_%y-%H.%M.%S)
date_formatted=$(date +%m_%d_%y-%H.%M.%S)
echo "This is the date and Time: " $date_formatted
#cp -iv $1 $2.$date_formatted # This command does not handle the file name that
# contains space
cp -iv "$1" "$2".$date_formatted # This can handle file name contains space
No comments:
Post a Comment