views:

21

answers:

2

can somebody explain me what does this error mean:

 > ./rank lines.in
'nknown option: `-
Usage: tcsh [ -bcdefilmnqstvVxX ] [ argument ... ].

this is my script rank:

#! /bin/tcsh -f
set line = `cat ${1}`
echo $line

I think that the problem I have is with first row #! /bin/tcsh -f I'm working on Windows! but after I wrote script on windows editor, I converted it using dos2unix rank, what can be the problem, thanks in advance for any help

A: 

I installed tcsh to my Linux box and run that script and it worked, so I guess your line breaks are wrong.

The error simply seems to mean that when the tcsh shell is called it receives invalid parameters. I think what it gets is the whole script as the parameter list. I tried changing -f to -g (not recognised as a tcsh parameter) and I got:

Unknown option: `-g'
Usage: tcsh [ -bcdefilmnqstvVxX ] [ argument ... ].

Notice how it still tells me the name of the invalid parameter?

Either that or your tcsh starts wrong. It is possible to give default parameters when starting a tcsh shell. Have you tried starting one?

But really, the only reason to learn tcsh would be if you need to maintain some age old tcsh scripts. And even then I would start by converting them to some other scripting language, if at all possible. If you want to learn shell scripting, try bash or bourne shell. There are many reasons why tcsh will just make you mad.

Makis
+1  A: 

I don't think your dos2unix worked. It appears you've still got a \r at the end of the hash-bang line that it doesn't like. It looks like it's seeing /bin/tcsh -f\r, interpreting that as /bin/tcsh -f -\r, and then attempting to print the error message:

Unknown option: `-\r'

The \r is causing the end quote to appear at the beginning of the line. If you want to see exactly what's in your file try cat -A ./rank to print all hidden characters. You'll probably see

#! /bin/tcsh -f^M$
John Kugelman