The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 2 03-17-2009 01:17 AM
Accessing PL/SQL OUT variables in Korn Shell Script bright_future UNIX for Advanced & Expert Users 4 12-02-2008 12:02 PM
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 03:31 PM
Accessing var from .profile into shell script videsh77 Shell Programming and Scripting 7 05-28-2005 12:21 PM
Accessing the home directory in shell script krishan SUN Solaris 1 05-21-2005 12:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-19-2008
The Observer The Observer is offline
Registered User
  
 

Join Date: May 2008
Posts: 18
Accessing the parameters of a shell script

Hi,

I have one situation. I am developing a shell script to which parameters will be passed from a Web based User Interface using some Business Process(BP).There are some 6 parameters for which user will enter the values in UI. These values will be passed to script by BP in the form - <parameter_name>, <value>. Out of 6, atleast one parameter is Mandatory to enter. My difficulty is how to access these parameter values. I thought of something like this. --

If [[echo $* | cut -f1 -d, == "PLANT"]]; then
PLANT=`echo $* | cut -f2 -d , `
fi

If [[echo $* | cut -f1 -d, == "DIRECTION"]]; then
DIRECTION=`echo $* | cut -f2 -d , `
fi

But, here my doubt is after the script identified that the string before (,) in any one parameter is PLANT, how is it going to identify the value after that comma & store in variable PLANT. It might also happen that it may take value in any other parameter after comma & store in PLANT variable as '$*' implies any parameter passed to the script.

I am not able to understand what logic to implement. Please help.
  #2 (permalink)  
Old 06-19-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
One good way is to use getopts with a case statement, rather than trying to find things blindly. If a parm is required, then in the case that matches it, set a variable like REQUIRED=1, so you can test for it later on.
  #3 (permalink)  
Old 06-20-2008
The Observer The Observer is offline
Registered User
  
 

Join Date: May 2008
Posts: 18
Can you please elaborete further ?

My requirement is like - if I find the string "PLANT" in one of the parameters which is coming in the format as - PLANT,<value> then I should take the <value> ( which is coming immediately after PLANT string with (,) as delimiter between them ) & store it in one variable known as PLANT.

It seems simple but due to the problem which I specified above , it will definitely fail. So, I need to implement some different logic.

If you think getopts will work in this case, can you please explain with example ?

Thanks.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0