Parsing Command Line Arguments In C shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing Command Line Arguments In C shell script
# 1  
Old 04-17-2013
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.
# 2  
Old 04-17-2013
Why don't you post the script you have written so far, using code tags?
# 3  
Old 04-17-2013
Code:
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

# 4  
Old 04-17-2013
I am not a csh programmer. Smilie

But maybe I can help anyway. Would something like the following work:
Code:
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.
# 5  
Old 04-17-2013
I think grep works only on file and not on string.
I might be wrong...Smilie
# 6  
Old 04-17-2013
You can verify grep works on stdin:
Code:
$ 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.
# 7  
Old 04-18-2013
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.

Code:
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to iterate all command line arguments

Hi guys, I am having trouble with this script. What i want it to do is to iterate all command line arguments in reverse order. The code below does this fine but i need the output to print the words on separate lines instead of one line: #!/bin/bash #Takes in the arguments and displays them... (7 Replies)
Discussion started by: pipeline2012
7 Replies

2. Programming

How to pass the command line arguments to the shell script in c language?

hi, I am new in the shell script, and c programming with linux. I am looking to pass the arguments in c program that should be executed by the shell script. e.g. #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { int i; for (i=1;i<argc; i++) { ... (2 Replies)
Discussion started by: sharlin
2 Replies

3. Programming

Parsing command line arguments in Python

Hi, I've a python script called aaa.py and passing an command line option " -a" to the script like, ./aaa.py -a & Inside the script if the -a option is given I do some operation if not something else. code looks like ./aaa.py -a . . if options.a ---some operation--- if not options.a... (1 Reply)
Discussion started by: testin
1 Replies

4. Shell Programming and Scripting

How to use case and command line arguments in shell script?

Hi... can anyone please help me out in using the CASE and command line argument in shell script... i am bit new to shell scripting...below i have explained my proble with example... say i have an executable file with name 'new1.sh' and there are 3 functions in it a(), b() and c()....and there... (5 Replies)
Discussion started by: swap21783
5 Replies

5. Shell Programming and Scripting

Shell script command line arguments

Hello All, i am known to the limitation of different shells while passing more than 9 command line arguments i just tried the example below i do see my current shell is tcsh echo $SHELL /bin/tcsh so if i make my script executable and run it output is ... (6 Replies)
Discussion started by: Deepak Dutt
6 Replies

6. UNIX for Dummies Questions & Answers

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (5 Replies)
Discussion started by: ajaira
5 Replies

7. UNIX for Advanced & Expert Users

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (1 Reply)
Discussion started by: ajaira
1 Replies

8. Shell Programming and Scripting

Bourne Shell Script that only takes command line arguments

Does anybody know how to Accept a “userid” as a command line argument on a Unix Bourne Shell Script? The output should be something like this: User userid has a home directory of /path/directory the default shell for this user is /path/shell (1 Reply)
Discussion started by: ajaira
1 Replies

9. Shell Programming and Scripting

Help parsing command line arguments in bash

Looking for a little help parsing some command line arguments in a bash script I am working on, this is probably fairly basic to most, but I do not have much experience with it. At the command line, when the script is run, I need to make sure the argument passed is a file, it exists in the... (3 Replies)
Discussion started by: Breakology
3 Replies

10. UNIX for Advanced & Expert Users

Parsing the command line arguments

Is there a way to get the command line arguments. I am using getopt(3) but if the arguments are more than one for a particular option than it just ignores the second argument. For eg ./a.out -x abc def now abd will be got with -x using getopt "( x : )" and string abc\0def will get stored... (7 Replies)
Discussion started by: jayakhanna
7 Replies
Login or Register to Ask a Question