Parsing Command Line Arguments In C shell script

]I have a string like "/abc/cmind/def/pq/IC.2.4.6_main.64b/lnx86" and this string is given by user. But in this string instead of 64b user may passed 32 b an i need to parse this string and check wether its is 32b or 64 b and according to it i want to set appropriate flags.

How will i do this using getopts as i am not getting the usage of getopts or there is any other way of doing this? I am writing a script in c shell.

Why don't you post the script you have written so far, using code tags?

if ( $#argv != 5 ) then
 echo "Usage: makeLocalHier platform dir_to_install RDHier QAHier ClientName"
 echo "e.g. : makeLocalHier lnx86 /home/codecatcher/test/temp /abc/cmind/def/gh/IC616-64b/main/lnx86 /hm/cmind/cic/PD/IC616-64b/main/lnx86 # here user can give 32b instead of 64 b codecatcher "
  exit 1
endif

set platform = $1 
set root_dir = $2 
set RD_Hier = $3 
set QA_Hier = $4
set client_name = $5


mkNewXStreamHier $platform $root_dir $RD_Hier $QA_Hier

set var = $?
if ( $var == 0 ) then
  echo " Hierarchy is created " 
else 
   echo " Hierarchy is Not Created "
     exit 1 
endif

if ( $platform == lnx86) then
set port="lnx86"
setenv MY_32bit_OA_PORT linux_rhel50_gcc44x_32
setenv MY_64bit_OA_PORT linux_rhel50_gcc44x_64

elseif ( $platform == sun4v ) then
set port = "sun4v"
setenv MY_32bit_OA_PORT sunos_58_32
setenv MY_64bit_OA_PORT sunos_58_64

else if ( $platform == "AIX" ) then
set port = "ibmrs"
setenv MY_32bit_OA_PORT aix_53_32
setenv MY_64bit_OA_PORT aix_53_64

else 
  echo " WARNING !!!!!!    Unknown Platform .... " 
endif

setenv DFII_HIER  $root_dir
setenv 64BIT true  # here i want to set if user gives 32b then only 32BIT flag should be set true

I am not a csh programmer. :mad:

But maybe I can help anyway. Would something like the following work:

echo "$RD_Heir" | grep -q 32b
if ( $? == 0 ) then
  setenv 32BIT true
else 
  setenv 64BIT true
endif

I don't think you need to use getopts.

I think grep works only on file and not on string.
I might be wrong...:mad:

You can verify grep works on stdin:

$ echo xxx | grep y
$ echo xxx | grep x
xxx

In most cases, grep loves stdin, does not need input from a file. Give it a try. grep is one of your best friends for writing scripts.

I have written this small script in c shell and i am getting an error " Badly Placed ()'s " .This is just a small snippet of my script where i am getting an error.

if ( $platform == lnx86 ) then
set port = "lnx86"
setenv MY_32bit_OA_PORT linux_rhel50_gcc44x_32
setenv MY_64bit_OA_PORT linux_rhel50_gcc44x_64

# error starts from here

elseif ( $platform == sun4v ) then
set port = "sun4v"
setenv MY_32bit_OA_PORT sunos_58_32
setenv MY_64bit_OA_PORT sunos_58_64

else if ( $platform == ibmrs ) then
set port = "ibmrs"
setenv MY_32bit_OA_PORT aix_53_32
setenv MY_64bit_OA_PORT aix_53_64

else 
  echo " WARNING !!!!!!    Unknown Platform .... " 
endif

One part says "else if"
The other part says "elseif"

Since I don't do csh, I don't know which is correct, but one of them must be wrong.

what is wrong in this snippet of script??

if ($platform != ( "lnx86" || "sun4v" || "ibmrs" ) )  then
   echo " WARNING!!!!!!!   UNknown Platform "

It's probable ( "lnx86" || "sun4v" || "ibmrs" ) is incorrect. Try this untested alternative way (courtesy of non-csh user :)):

switch ($platform)
  case "lnx86":
  case "sun4v":
  case "ibmrs":
    breaksw
  default:
    echo " WARNING!!!!!!!   UNknown Platform "
    breaksw
endsw
switch ($platform)
  case "lnx86":
  case "sun4v":
  case "ibmrs":
    breaksw
  default:
    echo " WARNING!!!!!!!   UNknown Platform "
    breaksw
endsw

This code is not working properly. When i give wrong platform instead of showing Warning message . It says " PATHecho : undefined variable "

---------- Post updated at 03:11 PM ---------- Previous update was at 03:11 PM ----------

switch ($platform)
  case "lnx86":
  case "sun4v":
  case "ibmrs":
    breaksw
  default:
    echo " WARNING!!!!!!!   UNknown Platform "
    breaksw
endsw

This code is not working properly. When i give wrong platform instead of showing Warning message . It says " PATHecho : undefined variable "

$ uname
Linux
$ cat test.sh
#!/bin/csh
set platform = "xxx"

switch ($platform)
  case "lnx86":
  case "sun4v":
  case "ibmrs":
    breaksw
  default:
    echo ' WARNING! UNknown Platform '
    breaksw
endsw
$ ./test.sh
 WARNING! UNknown Platform