我正在尝试 运行 -vx 模式下的脚本,但出现错误

I am trying to run a script in -vx mode , but getting error

" ././tst.ksh: line 16: ONL P BL9_RATED_EVENT_D 1,295 780 4,063,232 60 LOCA SYST AUTO: 无法打开 [没有这样的文件或目录] "

我正在尝试以 -vx 模式执行以下脚本 我不明白为什么在输出中我得到这个

!/bin/ksh -xv

    #for i in `cat /tefnfs/tef/tools/tooladm/Users/Jithesh/prd3cust.log | grep ONL | column -t`
    while i= read -r line
    do
    echo $i
    stat=`echo $i | cut -d" " -f1`
    typ=`echo $i | cut -d" " -f2`
    tbs=`echo $i | cut -d" " -f3`
    tot=`echo $i | cut -d" " -f4`
    free=`echo $i | cut -d" " -f5`
    lrg=`echo $i | cut -d" " -f6`
    fr=`echo $i | cut -d" " -f7`
    Ext=`echo $i | cut -d" " -f8`
    All=`echo $i | cut -d" " -f9`
    spc=`echo $i | cut -d" " -f10`
    done < `cat /tefnfs/tef/tools/tooladm/Users/Jithesh/prd3cust.log | grep ONL | column -t`
+ cat /tefnfs/tef/tools/tooladm/Users/Jithesh/prd3cust.log | grep ONL | column -t+ cat /tefnfs/tef/tools/tooladm/Users/Jithesh/prd3cust.log
+ column -t
+ grep ONL
././tst.ksh: line 16: ONL  P  BL9_RATED_EVENT_D  1,295  780  4,063,232  60  LOCA  SYST  AUTO: cannot open [No such file or directory]

有些问题我会在这里解释一下。
读取命令将命令后给出的变量归档。在您的代码中, line 是填充的变量的名称, i = 不属于此处。第一个改进是:

while read -r i                           
do                                        
    echo $i                               
    stat=`echo $i | cut -d" " -f1`        
    typ=`echo $i | cut -d" " -f2`         
    tbs=`echo $i | cut -d" " -f3`         
    tot=`echo $i | cut -d" " -f4`         
    free=`echo $i | cut -d" " -f5`        
    lrg=`echo $i | cut -d" " -f6`         
    fr=`echo $i | cut -d" " -f7`          
    Ext=`echo $i | cut -d" " -f8`         
    All=`echo $i | cut -d" " -f9`         
    spc=`echo $i | cut -d" " -f10`        
done < /tefnfs/tef/tools/tooladm/Users/Jithesh/prd3cust.log 

最后一行我也改了。 while 循环想要从文件中读取,而不是从命令的输出中读取。
注意:Bash 个示例会让您感到困惑。当你想将命令的输出重定向到 while 循环时,你可以在 Bash 中使用一些特殊的语法。 在 Bash 中,您将需要它,以便在完成 while 循环后知道 while 循环中设置的变量。
对于您的情况,ksh,您可以通过从命令开始并将其重定向到 while 循环来解决它。
在不修复逻辑的情况下修复代码给出

cat /tefnfs/tef/tools/tooladm/Users/Jithesh/prd3cust.log | grep ONL | column -t | while read -r i
do
    echo $i
    stat=`echo $i | cut -d" " -f1`
    typ=`echo $i | cut -d" " -f2`
    tbs=`echo $i | cut -d" " -f3`
    tot=`echo $i | cut -d" " -f4`
    free=`echo $i | cut -d" " -f5`
    lrg=`echo $i | cut -d" " -f6`
    fr=`echo $i | cut -d" " -f7`
    Ext=`echo $i | cut -d" " -f8`
    All=`echo $i | cut -d" " -f9`
    spc=`echo $i | cut -d" " -f10`
done

使用 column -t 没有帮助。在尝试将字段拆分为 space 之前,您需要先用一个 space 分隔字段。您需要将制表符替换为 space,并将多个 space 压缩为一个 space。 您可以为此使用 expand -1 | tr -s " "。 我想建议用符号 $(subcommand) 替换 backtics,但您可以使用 read 命令分配变量。 我的建议是

grep ONL /tefnfs/tef/tools/tooladm/Users/Jithesh/prd3cust.log | expand -1 | tr -s " " |
while read -r stat typ tbs tot free lrg fr Ext All spc; do
        echo "Processed line starting with ${stat}"
done

现在你应该在 while 循环中做一些事情。每次 while 循环处理下一行时,变量都会更改。在 while 循环之后,变量将填充最后一行处理的值。