0

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

..... ... .

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.