CENTOS 7与红帽企业Linux服务器版本6.7

时间:2017-10-16 11:47:48

标签: 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

1 个答案:

答案 0 :(得分: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

感谢您的帮助