Tuesday, 6 December 2016

Shell Script 6

Final version cpdate
#!/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)
echo "This is the date and Time: " $date_formatted

date_formatted=$(date +%Y-%m-%d_%H.%M%S)
file_extension=$(echo "$1" | awk -F . '{print $NF}')
file_name=$(basename $1 .$file_extension)
cp -iv $1 $file_name-$date_formatted.$file_extension
~

No comments:

Post a Comment