使用内部rpm规范文件时,date命令给出错误的输出 [英] date command is giving erroneous output while using inside rpm spec file

查看:55
本文介绍了使用内部rpm规范文件时,date命令给出错误的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装我的软件包之前,我必须执行一些必要的步骤,例如备份以前的数据存储快照.为此,我使用了%pre脚本,如下所示.

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
#!/bin/sh
--------
--------
stamp=`date +%Y%m%d%H%M%S`
echo ${stamp}
-------------
-------------

输出如下:20161103123325OURCE它随日期一起打印一些随机字符.我的规格文件中的任何地方都没有"OURCE".

The output is as follows: 20161103123325OURCE It is printing some random characters along with date. "OURCE" is not present anywhere in my spec file.

同一脚本可以完美地用作独立脚本.该平台是CentOS7.

The same script works perfectly as standalone. The platform is CentOS7.

推荐答案

rpmbuild知道一整套宏.显然,某个宏定义为:

rpmbuild knows a whole set of macros. Apparently a certain macro is defined as:

%S = %SOURCE

我没有找到告诉rpmbuild不要扩展该宏的内容.但是有一种方法可以欺骗他不要这样做.我知道这是一个小解决方法,但这是我能想到的最好的方法:

I didn't manage to find something that tells rpmbuild not to expand that macro; 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')

  • 请注意,我用推荐的 $()调用替换了反引号
  • 我刚刚插入了两个''将字符串分成两部分;这样可以避免宏替换.
  • 这篇关于使用内部rpm规范文件时,date命令给出错误的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆