Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CENTOS 7与Red Hat Enterprise Linux Server 6.7版之间不匹配_Linux_Bash_Centos_Redhat - Fatal编程技术网

CENTOS 7与Red Hat Enterprise Linux Server 6.7版之间不匹配

CENTOS 7与Red Hat Enterprise Linux Server 6.7版之间不匹配,linux,bash,centos,redhat,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_lin

我有一个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
第56行:-2:子字符串表达式<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

非常感谢您的帮助

我想删除最后两个字符…您能帮我重写这段代码吗?CentOS 7将bash从4.1升级到4.2(这是第一个允许负索引的版本)。