Sponsored Content
Top Forums Shell Programming and Scripting ksh processing options and parameters Post 302815273 by BeefStu on Friday 31st of May 2013 02:50:07 PM
Old 05-31-2013
ksh processing options and parameters

I have a requirement where I need to process both options and parameters.

command line call
Code:
ie xxx.ksh -sid TEST1 -search_str LOCKED  user1 user2 .....

I am using the following peice of code but I am usure how I can loop through all my parameters user1, user2, ... Note at the minium there were
be at least "user1"

Can somebody provide and example.

Code:
while [ $# -gt 0 ]
do
     case $1 in
     -+([sS]*(id|ID)))
          shift
          export ORACLE_SID=$1
          ;;
     -+([sS]*(earch_string|EARCH_STRING)))
          shift
          export SEARCH_STRING=$1
          ;;
       *) shift ;;
   esac
done

Thanks to all who answer

---------- Post updated at 02:50 PM ---------- Previous update was at 11:29 AM ----------

My solutuon. Its not fancy but appears to work. Any elegant solutuons are more than welcome

Code:
 
#!/bin/ksh
 
let i=0
set -A parameters
typeset -L1 first_char_in_last_arg

while [ $# -gt 0 ]
do
     case $1 in
     -+([sS]*(id|ID)))
          shift
          export ORACLE_SID=$1
          shift
          ;;
     -+([sS]*(earch_string|EARCH_STRING)))
          shift
          export SEARCH_STRING=$1
          shift
          ;;
       *)
         first_char_in_last_arg="$1"
         if [ "$first_char_in_last_arg" != "-" ]
         then
            parameters[$i]="$1"
            ((i=i+1))
         fi
         shift ;;
   esac
done
for i in ${parameters[@]}
do
   echo $i
done


Last edited by joeyg; 05-31-2013 at 04:07 PM.. Reason: code not icode... (jg just adjusted)
 

9 More Discussions You Might Find Interesting

1. Programming

parameters from my program in c to a .ksh script

hi.. this is my question: it is possible transfer parameters from my program written in C to a .ksh script? how can i do it? i have a program in C, what is called from a .ksh script, and i need what the C program returns some values (parameters) please, help me - any idea thanks ... (2 Replies)
Discussion started by: DebianJ
2 Replies

2. Shell Programming and Scripting

getopts takes options for parameters

Here is my post with a question about getopts. I am running korn shell on Solaris 5.8. I am trying to ensure that certain options require a parameter, which is easy enough. I have found that if multiple options are entered on the command line together, but the parameter for one of the options is... (1 Reply)
Discussion started by: UCD-Randy
1 Replies

3. UNIX for Dummies Questions & Answers

ksh: verifying number of parameters passed

hi all, i have a ksh script that takes up to 3 parameters -- only 2 of which are required. what's the simplest way to check if the user passed 2 or 3 parameters? if 3 parameters are not null then do this elif 2 parameters are not null then do this else echo "you need at least 2... (5 Replies)
Discussion started by: ankimo
5 Replies

4. Shell Programming and Scripting

KSH script -text file processing NULL issues

I'm trying to strip any garbage that may be at the end of my text file and that part is working. The problem only seems to be with the really long lines in the file. When the head command is executed I am directing the output to a new file. The new file always get a null in the 4096 position but... (2 Replies)
Discussion started by: geauxsaints
2 Replies

5. Shell Programming and Scripting

Get Options and Parameters

Hi there. Could someone explain how do i get the options separated from the arguments. My problem is that i have a lot of options and in all of those options i need to have the parameters available to use in that option and all the others. How can i take the arguments before i cycle throw the... (4 Replies)
Discussion started by: KitFisto
4 Replies

6. Shell Programming and Scripting

Processing files using ksh shell

I need to write a Shell Script to process a huge folder of nearly 20 levels.I have to process each and every file and check which files contain lines like select insert update When I mean line it should take the line till I find a semicolon in that file. I should get a result like this ... (1 Reply)
Discussion started by: 20033716
1 Replies

7. Shell Programming and Scripting

Why double quotation marks doesn't work in ksh function parameters passing?

I'm working on AIX 6, ksh shell. The parameters are some strings quotated by double quotation marks which from a file. They are quotated because there may be spaces in them. Example: "015607" "10" " " "A"I want to pass these parameters to a shell function by writing the following command: ... (4 Replies)
Discussion started by: Shimmey
4 Replies

8. Shell Programming and Scripting

Processing Multiple Arguments in Command Line Options

Hi All, I am new to scripting. Could you please assist me . Here is my requirement. I have written a script that has 2 option flags defined. -l) calls some function with the arguments passed in front of -l -r) calls second function with the arguments passed in front of -r *) calls the... (7 Replies)
Discussion started by: Jay Deshpande
7 Replies

9. UNIX for Dummies Questions & Answers

Crontab not processing parameters sent to script.

Hello All, I'm running Debian on a ThinkPad X1/2G and all seems to be running well. However, it's got a SSD that needs the trim command run at regular intervals. I'm implementing this using cron and a shell script, as recommended. The cron job entries are as follow: 0 * * * *... (8 Replies)
Discussion started by: ASGR
8 Replies
shift(1)							   User Commands							  shift(1)

NAME
shift - shell built-in function to traverse either a shell's argument list or a list of field-separated words SYNOPSIS
sh shift [n] csh shift [variable] ksh * shift [n] DESCRIPTION
sh The positional parameters from $n+1 ... are renamed $1 ... . If n is not given, it is assumed to be 1. csh The components of argv, or variable, if supplied, are shifted to the left, discarding the first component. It is an error for the variable not to be set or to have a null value. ksh The positional parameters from $n+1 $n+1 ... are renamed $1 ..., default n is 1. The parameter n can be any arithmetic expression that evaluates to a non-negative number less than or equal to $#. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 shift(1)
All times are GMT -4. The time now is 11:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy