The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Check if parameter passes in contains certain string bcunney Shell Programming and Scripting 9 3 Weeks Ago 06:54 AM
making script shary Shell Programming and Scripting 2 06-03-2007 01:16 PM
Need help making a script npereira Shell Programming and Scripting 2 01-06-2007 09:14 AM
Script to check for a file, check for 2hrs. then quit mmarsh UNIX for Dummies Questions & Answers 2 09-16-2005 11:46 AM
How to check parameter variable? negixx Shell Programming and Scripting 4 06-10-2005 02:37 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-06-2006
Registered User
 

Join Date: Feb 2006
Location: JP.Tokyo
Posts: 30
Help with making a parameter check script.

I am making a script to check the parameters, but it seems that I can't catch the parameters by loop.

[tester@test0102d test]$ cat sendmsg.sh
#!/bin/sh

## Parameter Check
i=0
max=$#
while [ $i -lt $max ]
do
PARAM[${i}]=$${i}
i=`expr ${i} + 1`
echo ${PARAM[${i}]}
done

How can I get the $1, $2, $3 by loop and set their values to PARAM[${i}]?

Thank u in advance.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-06-2006
Klashxx's Avatar
HP-UX/Linux/Oracle
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 371
Try.


count=1
for i in $@
do
PARAM[${count}]=${i}
(( count += 1 ))
done



Cheers.
Reply With Quote
  #3 (permalink)  
Old 03-06-2006
Registered User
 

Join Date: Feb 2006
Location: JP.Tokyo
Posts: 30
Thank u in advance!

Test OK !
[tester@test0102d test]$ cat sendmsg.sh
#!/bin/sh

## Parameter Check
cnt=0
for i in $@
do
PARAM[${cnt}]=${i}
echo ${PARAM[${cnt}]}
cnt=`expr ${cnt} + 1`
done


[tester@test0102d test]$ sh sendmsg.sh test test1 test2
test
test1
test2
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0