shell - cut:必须指定字节、字符或字段的列表

shell - cut:必须指定字节、字符或字段的列表

我尝试以相反的顺序获取命令行参数的输出。但是这样做时出现了错误。

这是代码:

#!/bin/bash

str=$@
len=$#
space=" "
echo "No. of arguments = $len"
echo "Entered arguments = $str"
while [ $len -ne 0 ]
do
        tmp=`echo $str | cut -d " " f $len`
        rev=$rev$tmp$space
        len=`expr $len - 1`
done
echo "Arguments in reverse = $rev"

当我运行脚本时,出现此错误:

robin@robin-VirtualBox:~/lx$ ./s1.sh one two three
No. of arguments = 3
Entered arguments = one two three
cut: you must specify a list of bytes, characters, or fields
Try 'cut --help' for more information.
cut: you must specify a list of bytes, characters, or fields
Try 'cut --help' for more information.
cut: you must specify a list of bytes, characters, or fields
Try 'cut --help' for more information.
Arguments in reverse =    

答案1

您只是在参数-前漏掉了一个符号。在进行了这一修改后,我能够运行您的脚本并使其正常运行。-fcut

相关内容