[Gllug] csh shell scripting woes

Stig Brautaset stigbrau at start.no
Thu Mar 14 00:49:42 UTC 2002


* Tom Gilbert <tom at linuxbrit.co.uk> spake thus:
>> should take either of the optional arguments -i or -f. The problem he is
>> facing is that the shell has its own interpretation of e.g. -f, so the
>> script fails.
>> 
>> Both he and I have tried every combination of --, -f, -b, -c etc we
>> could think of at the end of #!/bin/csh which obviously is the first
>> line. We *have* read the manpage, but if it contains a clear explanation
>> of the problem, then I for one can't find it. 
> 
> Er. Why are you putting arguments there?

Because I am blank at what else to do? I have checked the chapters on
shell-scripting of two different linux books, read the manpage, and the
only thing I could think of was that I remember some perl coders
advocating arguments in the hashbang, e.g. "#!/usr/bin/perl -w" or some
other random letter that I cannot remember. 

The script he is writing should have the synopsis:

	rename [OPT] src [...] dst

where OPT could be any of "-f" or "-i". The problem with this is that if
you invoke a csh-script with "-f" as one of the arguments, it chokes and
exits with this error message:

if: Missing file name.

What the hell this means is completely uncomprehensible to me, because
the manpage says that the "-f" argument will simply make the script
skip reading the startup file ~/.cshrc...

Hence, I thought that there was some magic trick one could use in the
hashbang that would tell the shell to ignore any arguments, other than
putting them in $argv. The description of "-b" seems to be what he
wants, but it Does Not Work(TM) the way we understand it to.

His script works just as intended if one lets OPT be either of "f" or
"i", i.e. without the preceeding "-". As stated before, the only problem
he is facing is that csh behaves strangely if it sees "-f" in the
argument list.

Stig
-- 
brautaset.org

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list