mles
mles

Reputation: 3466

timestamp=$(date +%Y%m%d) not evaluated in shell script

I have a shell script that calls another shell script. One of the parameters is the output filename which I want to prefix with a timestamp. So far I've been doing it like this:

#!/bin/bash -e

bash resign "$(date +%Y%m%d)_UI_Touch_SU_test_$version.ipa"

This is working fine. The resulting filename is 20151029_UI_Touch_SU_test_21.6.5212.ipa. However I want to customize the filename further and have a date variable:

#!/bin/bash -e

timestamp=$(date +%Y%m%d)
bash resign "$timestamp_UI_Touch_SU_test_$version.ipa"

This is not working. The resulting filename is 21.6.5212.ipa. How do I set the date variable correctly?

Upvotes: 0

Views: 1508

Answers (1)

Manuel Barbe
Manuel Barbe

Reputation: 2164

Try

bash resign "${timestamp}_UI_Touch_SU_test_${version}.ipa"

You need the {} to delimit the variable from the rest of the string.

Edit: Note, that $version.ipa also works without the curly braces, since the dot . is not a valid variable character in bash (in contrast the underscore _ is). However, I think it is good practise to use the curly braces there as well.

Upvotes: 5

Related Questions