CENTOS 7与Red Hat Enterprise Linux Server 6.7版之间不匹配
我有一个bash脚本,它可以在CENTOS上正常工作,但是当我想在Red Hat Enterprise Linux上运行该脚本时,我遇到了以下错误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
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(这是第一个允许负索引的版本)。