1748202 Members
3008 Online
108759 Solutions
New Discussion юеВ

Input parameters

 
SOLVED
Go to solution
Kris_5
Occasional Advisor

Input parameters

Hi Folks,

I need to write a shell script which will take min. 7 input parameters and there is no maximum limit for input parameters. I have to read the parameters 8 and above into one variable. Can some body help me how to read the parameters into one variable. Thanks in adv.

Kris
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Input parameters

Hi:

If I understand your question, then this should do it:

#!/usr/bin/sh

A=$1
B=$2
C=$3
D=$4
E=$5
F=$6
G=$7
shift 7
H=$@

${H} then contains all the parameters above 7.
If it ain't broke, I can fix that.
Craig Rants
Honored Contributor

Re: Input parameters

I agree with Clay, shift will do it. Run a trial throught this script and you get a good output

#!/bin/sh
echo $1
echo $2
echo $3
echo $4
echo $5
echo $6
echo $7
shift 7
echo $*

sh echo.sh a b c d e f g h i j

results...
a
b
c
d
e
f
g
h i j

You can modify from there.
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Wodisch
Honored Contributor

Re: Input parameters

Hello Kris,

how about this:

#!/usr/bin/sh

while [ -z "$p7" ]; do
echo "enter data:\c"
read p1 p2 p3 p4 p5 p6 p7 rest
done;

echo "1. word: $p1"
echo "2. word: $p2"
echo "3. word: $p3"
echo "4. word: $p4"
echo "5. word: $p5"
echo "6. word: $p6"
echo "7. word: $p7"
echo "8+ word: $rest"

HTH,
WOdisch