Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-14-2010
Registered User
 

Join Date: Jan 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Question Dynamic number of parameter

Hi all
Is there away to create a script with dynamic number of parameter..
like the kill command in UNIX
kill -9 xxx xxx
cheers
Sponsored Links
    #2  
Old 03-14-2010
dennis.jacob's Avatar
Registered User
 

Join Date: Feb 2007
Location: Singapore/Cochin
Posts: 871
Thanks: 0
Thanked 10 Times in 9 Posts
Something like this???



Code:
ps -ef | grep 'pattern_to_search' | awk '{ print $1 }' | xargs kill -9

Sponsored Links
    #3  
Old 03-14-2010
Registered User
 

Join Date: Jan 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
no i didn't mean that i mean if i want to create new script which will ptree the process and log the output then kill it
for example
script.sh -9 xxxx
script.sh -9 xxxx yyyy zzzz
    #4  
Old 03-14-2010
thegeek thegeek is offline Forum Advisor  
Registered User
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 1,090
Thanks: 13
Thanked 37 Times in 35 Posts
You dont have to do anything big.

go through the following which will help you.,

Code:
$ bash a.sh -9 1 3 4 5
All arguments: -9 1 3 4 5
name of script is a.sh
first argument is -9
second argument is 1
seventeenth argument is -97
number of arguments is 5


Code:
$ cat a.sh 
echo "All arguments: $@"

echo name of script is $0
echo first argument is $1
echo second argument is $2
echo seventeenth argument is $17
echo number of arguments is $#

Refer this: Bash by example, Part 2
Sponsored Links
    #5  
Old 03-16-2010
Registered User
 

Join Date: Jan 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
thanks a lot guys
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sql dynamic table / dynamic inserts magedfawzy UNIX for Advanced & Expert Users 0 09-25-2009 03:37 PM
checking if parameter passed is a number magnia UNIX for Dummies Questions & Answers 2 07-20-2009 06:56 AM
how do I make dynamic parameter names? Or get the value of a parameter evaluated twi Awanka Shell Programming and Scripting 2 04-19-2007 09:37 PM
Parameter in UNIX restricting the number of lines that can be mailed superprg UNIX for Dummies Questions & Answers 2 08-23-2006 05:25 AM



All times are GMT -4. The time now is 03:48 AM.