linux - CENTOS 7 和 Red Hat Enterprise Linux Server 版本 6.7 之间不匹配

标签 linux bash centos redhat

我有一个 bash 脚本,它在 CENTOS 上运行良好,但是当我想在 Red Hat Enterprise Linux 上运行该脚本时,出现以下错误。

if [ "${line:(-2)}" == "nm" ]
 then
sub_sh=${line:31:8}
if [ $sub_sh != "test" ];
  then
sub_str=${line:0:10}
date_line=$(date --date=$sub_str '+%Y%m%d')
result=`expr $date_line - $yesterday`
if [ $result  -gt 1000 ];
then
 Rtime="${line##* }"
 pureqrt=${Rtime::-2}  #line 56

错误:

line 56: -2: substring expression < 0

最佳答案

我使用下面的脚本删除最后两个字符

#   in bash
#   pureqrt=${queryRtime::-2}
    pureqrt=$(echo $queryRtime | cut -d "m" -f 1)
----------------------------------------------
#command line 
 echo "2234ms" | cut -d "m" -f 1
 output : 2234

感谢您的帮助

关于linux - CENTOS 7 和 Red Hat Enterprise Linux Server 版本 6.7 之间不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46769601/

相关文章:

linux - 使用 pwm-ir-tx 模块时没有可用的用户空间 chardev

linux - 如何找出我在 go 老爹共享主机 ssh 上使用的发行版

python - 如何在python中执行两条语句之间插入1秒的时间间隔

linux - 如何运行从当前 rpm 规范文件安装 rpm 的 bash 脚本?

amazon-ec2 - 解压gzip文件消失?

Shell Script 和 yum,包不可用时怎么办。森托斯

linux - Linux 中 GetProcessIoCounters 的等价物是什么?

linux - 如何在 *nix 中登录时运行脚本?

linux - 使用 at(bash 终端)不执行命令

bash - `exit $?` 与 bash 中的 `exit` 有什么不同吗?