Reputation: 139
I want to replace the 20140118 with $DATE in "Personal_20140118D_1.zip"
is "Personal_"$DATE"D_1.zip" syntactically correct?
DATE=date +%Y%m%d
if [ ( $FILE == "Personal_20140118D_1.zip" ) -a ( $TODAY == "Sat" ) ]; then
..... ... .
Upvotes: 0
Views: 38
Reputation: 58838
To replace the first occurrence of the date in the variable:
date_file=${FILE/20140118/$DATE}
See man bash
for details.
Example:
$ date=`date +%Y%m%d`
$ file="Personal_20140118D_1.zip"
$ date_file=${file/20140118/$date}
$ echo "$date_file"
Personal_20140123D_1.zip
Upvotes: 1
Reputation: 328624
Yes. Quotes only protect spaces from becoming word separators. You can have them in any place. So these are all equivalent as long as a
and b
don't contain spaces:
ab
"a"b
"a""b"
a"b"
a"$var"b
a${var}b
I suggest to use "a${var}b"
, though since the other forms look confusing.
Upvotes: 1