Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
LOL! I didn't saw that. Now, its working fine. Thank you! –  Robin Apr 28 at 1:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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