5

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

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.