Dynamics param for script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dynamics param for script
# 1  
Old 01-09-2013
Dynamics param for script

Hi everyone,

I need a way to take the value of a parameter with a for lood. For example i execute the script with this parameter

Code:
./Script PARAM1 PARAM2 PARAM3 PRAM4

Code:
for i in <LIST OF PARAMETERS>
do
     PARAMETERS[i]=$<NUMBER OF PARAMETER>
done

How can i express <LIST OF PARAMETERS> and <NUMVER OF PARAMETERS>?

Thanks!

Sorry for my english.

NOTE: the numbers of parameters is not the same allways.

Last edited by radoulov; 01-09-2013 at 10:34 AM.. Reason: Code tags fixed.
# 2  
Old 01-09-2013
Consider the following:

Code:
#!/bin/sh

printf 'number of parameters: %d\n' $#

printf 'all parameters:\n'
printf '\t%s\n' "$@"

printf 'looping\n'

for p; do
  printf '\t%s\n' "$p"
done

It produces the following output with different parameters:

Code:
zsh-4.3.12[t]% ./params one two
number of parameters: 2
all parameters:
        one
        two
looping
        one
        two
zsh-4.3.12[t]% ./params three four five
number of parameters: 3
all parameters:
        three
        four
        five
looping
        three
        four
        five

If for <varname>; do ... doesn't work
with your shell, be more explicit:

Code:
for <varname> in "$@"; do ...

Some shells provide the getopts builtin for more advanced parameter parsing.
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Linux

Shell Script to generate Dynamic Param file Using SQL Plus Quey

Hi All, Can anyone give me Shell script sample script to generate Param file by Reading Values from SQL Plus query and it should assign those values to variables like.. $$SChema_Name='ORCL' Thanks in Advance... Srav... (4 Replies)
Discussion started by: Sravana Kumar
4 Replies

2. UNIX and Linux Applications

Microsoft Dynamics GP - Linux analog?

And if it exists, can it integrate with LDAP (for i know Microsoft Dynamics GP does not integrate with Microsoft Active Directory). (0 Replies)
Discussion started by: Xcislav
0 Replies

3. UNIX for Dummies Questions & Answers

sqlplus script out param

For starters, I have read the forums from top to bottom and cannot find a solution to this particular scenario. Just finished up two hours or scouring the archives. Here is my question which has been asked numerous times before but never fully explained for this particular solution: How do I pass a... (2 Replies)
Discussion started by: jwil0m0
2 Replies

4. UNIX for Dummies Questions & Answers

Script for reading filelist and preparing param file.

Hi All, Not sure if this would be in a dummies sectiin or advanced. I'm looking for a script if someone has doen something like this. I have list of files - adc_earnedpoints.20070630.txt adc_earnedpoints.20070707.txt adc_earnedpoints.20070714.txt adc_earnedpoints.20070721.txt... (2 Replies)
Discussion started by: thebeginer
2 Replies
Login or Register to Ask a Question