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

Rob*_*bin 5 command-line bash scripts

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

这是代码:

#!/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"
Run Code Online (Sandbox Code Playgroud)

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

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 =    
Run Code Online (Sandbox Code Playgroud)

jkt*_*123 8

你只是错过了-你的-f论点之前的标志cut。在进行这一修改后,我能够运行您的脚本并使其正常运行。