- Bash 4.1.17 (works with Cygwin)
Hello, I'm trying to pass a date to the --suffix option on the move (mv) command. I can pass a simple string (like my name), but I can't pass a date. If you run the script below, you will see that the mv command with the suffix = "$ var" works, but the suffix = "$ now" does not.
#!/bin/bash
dir="your directory goes here"
now="$(date "+%m/%d/%y")"
var="_CARL!!!"
echo "$now"
echo "$var"
cd "$dir"
touch test.txt
mkdir ./stack_question
touch ./stack_question/test.txt
mv -b --suffix="$var" test.txt ./stack_question/
The idea is that if test.txt already exists while trying to move the file, a suffix will be added to the file. Therefore, if you run this script with:
--suffix="$var"
you will see that the stack_question directory contains two files:
test.txt and test.txt_CARL !!!
But if you run this script with:
--suffix="$now"
you will see that the stack_question only contains
test.txt
Any help on this would be greatly appreciated!