3

I'm running an online store where I can put a variable versiontag to includes JS and CSS as a cachebuster. I. e.

styles.css?v2018_01

Wherein the 2018_01 is the version tag. Now I also have a CLI tool that makes it quick to set like so

mr config:set 'design/head/meta_version_tag' [insert_my_var_here]

And what I want to do is create a Bash alias that sets the variable to the Unix timestamp whenever it is run. I know I can get the Unix timestamp with date +%s.

So I would make an alias like this:

mr config:set 'design/head/meta_version_tag' date +%s

But the CLI interprets the date +%s as a string, rather than getting its output first.

So what I need is an output like this:

mr config:set 'design/head/meta_version_tag' 1519747390

And so my question is; how can I get the output of the unix datestamp in my alias?

2 Answers 2

6

Provided you use bash you can use Command Substitution:

mr config:set 'design/head/meta_version_tag' $(date +%s)

This will first run date +%s in a subshell and include the output as a string, see man bash under EXPANSION/Command Substitution:

Bash performs the expansion by executing command and replacing the command substitution with the standard output of the command, with any trailing newlines deleted.

There's no need to quote the command substitution (like you would normally do) in this case, as the output of date +%s doesn't have any whitespaces.

2

How about

mr config:set 'design/head/meta_version_tag' $(date +%s)

Or,

alias dothething='mr config:set "design/head/meta_version_tag" $(date +%s)'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .