动态设定执行在 systemd 中 service 的环境变数
以本部落格主题的新功能为例,新功能需要传一个名为 BLOG_VERSION
的环境变数,这样会把附加的信息写在页脚,可以直接验证是从那个 commit 生成的 (是的 我下午被 CloudFlare 的缓存坑了)
比方说我使用 git 的 short hash
和 commit date
,就可以按如下所写
$ bash -c 'export BLOG_VERSION="$(git rev-parse --short HEAD) $(git --no-pager log -1 --format="%ai")"; echo $BLOG_VERSION'
Bash option -c
1:
-c If the -c option is present, then commands are read from
the first non-option argument command_string. If there
are arguments after the command_string, the first argument
is assigned to $0 and any remaining arguments are assigned
to the positional parameters. The assignment to $0 sets
the name of the shell, which is used in warning and error
messages.
来源: