Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
google site



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

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Search this Thread
  #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
dj - the student
 

Join Date: Feb 2007
Location: Bangalore/Cochin
Posts: 860
Thanks: 0
Thanked 5 Times in 4 Posts
Something like this???



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

  #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: 927
Thanks: 6
Thanked 18 Times in 16 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
  #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
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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
iPhone: Locating the serial number, IMEI, and ICCID number Linux Bot OS X Support RSS 0 10-23-2008 10:50 PM
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 09:20 PM.