6

I am trying to get the output of the command line arguments in reverse order. But I am getting a error while doing so.

This is the code:

#!/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"

And when I run the script, I get this error :

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 =    
3
  • Wha...
    – Seth
    Apr 28, 2014 at 1:33
  • @Seth I am sorry, I had to. It was all a mess.
    – Robin
    Apr 28, 2014 at 1:35
  • Well you could have just edited it, but ok :)
    – Seth
    Apr 28, 2014 at 1:39

1 Answer 1

8

You are just missing the - sign before your -f argument to cut. I was able to run your script and have it function properly after making that one modification.

1
  • LOL! I didn't saw that. Now, its working fine. Thank you!
    – Robin
    Apr 28, 2014 at 1:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .