command line flags in csh

command line flags in csh

Post by Bob Michelett » Fri, 21 Sep 2001 07:04:29



I am trying to use command line flags with normal UNIX syntax, command -abc,
and split the flags into an array variable.  The following works but I can't
figure out how to handle the errors.  I'm working in IRIX 6.5.7.

#!/bin/csh
if ("$1" !~ -[a,b,c]*) then
echo "Usage bla bla bla"
exit
endif

set flag=`getopt abc $*`
echo $flag

I did find a way to trap errors in the 1st flag but I can't trap the 2nd
flag.
This is my first post.  I hope it's appropriate and formatted correctly.

Thanks,
Bob

 
 
 

command line flags in csh

Post by Bruce Barnet » Sat, 22 Sep 2001 21:30:09



> I am trying to use command line flags with normal UNIX syntax, command -abc,
> and split the flags into an array variable.  The following works but I can't
> figure out how to handle the errors.  I'm working in IRIX 6.5.7.

> #!/bin/csh
> if ("$1" !~ -[a,b,c]*) then
> echo "Usage bla bla bla"
> exit
> endif

> set flag=`getopt abc $*`
> echo $flag

Here is a code fragment for starters...

#!/bin/csh -f at the start.

set syntax = "usage: $0 [-b] [-a arg]"
# parse arguments
while ($#argv > 0)
       switch ($1)
          case -b:
             set b = 1
             breaksw

          case -a:
             if ($#argv < 2) then
                echo $progname": missing argument for $1"
                exit 1
             else
                set a = $2
             endif
             shift
             breaksw

          case -help:
          default:
             echo "$syntax"
             exit 1
       endsw
       shift
end

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.

 
 
 

1. csh with a command on the command line


:"    Except with the options -c, -i, -s or -t, the  first  nonop-
:     tion  argument  is  taken  to  be  the  name of a command or
:     script.  It is passed as argument zero, and subsequent argu-
:     ments  are  added  to  the argument list for that command or
:     script."
:Please explain these results. How can I run csh with a command as an
:argument?
:
:I am running SunOS 4.1.3.

It seems quite simply that in this instance the manual page is simply
wrong (at least for csh on SunOS). Csh only excepts scripts as its first
arguement, unless you specify the -c switch. Thus if you want to run a
command using csh use :

csh -c echo

Hope that helps
(all presently known standard and non-standard disclaimers apply)
--
Brian Blackmore, The University of Kent at Canterbury, United Kingdom.
Memories were made for remembering....

2. A Linux "Domain Server"?

3. Newbie: how to parse command line flags with -- OR -

4. Linux-X-library not found

5. csh: command line instead of script

6. 7 Need Developers

7. csh script command line args

8. Unix-socket-faq for network programming

9. DOSKEY like command line (sh and csh)

10. csh: command line instead of script

11. Multi-line command substitution (csh)

12. csh command line substitution question

13. sh, csh command line parsing