Conversion of time format could be done via date
utility:
On Linux (GNU coreutils):
$ date -d 'Oct 27 16:33:41 2013' '+%Y%m%d%H%M'
201310271633
On OS X (date
options taken from Darwin manpages available online):
$ date -j -f '%b %d %T %Y' 'Oct 27 16:33:41 2013' '+%Y%m%d%H%M'
201310271633
Your code should look like this (on OS X):
for f in "$@"
do
# convert video
HandBrakeCLI -i "$f" -o "/Users/J/Desktop/$(basename "$f" .AVI).mp4" -e x264 -q 20 -B 160
# read out creation date from source file
date_transfer=$(stat -f '%Sm' "$f")
# write creation date of source to converted file
touch -t $(date -j -f '%b %d %T %Y' "$date_transfer" '+%Y%m%d%H%M') /Users/J/Desktop/$(basename "$f" .AVI).mp4
done
Notice the quotes around $date_transfer
. Date wants to get the date as one parameter and shell would split parts of date_transfer
at spaces if the quotes were not present.