【问题标题】:A mismatch between CENTOS 7 and Red Hat Enterprise Linux Server release 6.7CENTOS 7 和 Red Hat Enterprise Linux Server 6.7 版本不匹配
【发布时间】:2018-03-27 22:22:53
【问题描述】:

我有一个 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

【问题讨论】:

  • 我想删除最后两个字符...你能帮我重写这段代码吗
  • 仅供参考,CentOS 7 将 bash 从 4.1 升级到 4.2(这是第一个允许负索引的版本)。

标签: linux bash centos redhat


【解决方案1】:

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

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

感谢您的帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-20
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    相关资源
    最近更新 更多