[英]date command is giving erroneous output while using inside rpm spec file
I have to perform some necessary steps before installing my package, such as taking back up of previous datastore snapshot. 安装软件包之前,我必须执行一些必要的步骤,例如备份以前的数据存储快照。 For that purpose I'm using a %pre script as follows.
为此,我使用%pre脚本,如下所示。
%pre
#!/bin/sh
--------
--------
stamp=`date +%Y%m%d%H%M%S`
echo ${stamp}
-------------
-------------
The output is as follows: 20161103123325OURCE It is printing some random characters along with date. 输出如下:20161103123325OURCE它正在打印一些随机字符以及日期。 "OURCE" is not present anywhere in my spec file.
我的规格文件中的任何地方都不存在“ OURCE”。
The same script works perfectly as standalone. 相同的脚本非常适合独立运行。 The platform is CentOS7.
该平台是CentOS7。
rpmbuild knows a whole set of macros. rpmbuild知道一整套宏。 Apparently a certain macro is defined as:
显然,某个宏定义为:
%S = %SOURCE
I didn't manage to find something that tells rpmbuild not to expand that macro; 我没有设法告诉rpmbuild不要扩展该宏。 but there is a way in tricking him not to do so.
但是有一种方法可以欺骗他不要这样做。 I know this is a little workaround, but it's the best I could come up with:
我知道这是一个小解决方法,但这是我能想到的最好的方法:
stamp=$(date '+%Y%m%d%H%M%''S')
$()
invocation $()
调用替换了反引号 If you escape the percent '%' in your date command with a second percent symbol '%%' as described at the following link, that should correct the behavior you're seeing with expanding %S to "OURCE" as you're seeing in your output. 如果您在日期命令中使用第二个百分号“ %%”对百分号“%”进行了转义(如以下链接所述),则可以通过将%S扩展为“ OURCE”来更正您所看到的行为在您的输出中。
stamp=`date +%%Y%%m%%d%%H%%M%%S`
See section "Writing a Macro" here http://rpm.org/user_doc/macros.html 请参阅http://rpm.org/user_doc/macros.html中的 “编写宏”部分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.