Computing.Net > Forums > Unix > How to take arguments in unix

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to take arguments in unix

Reply to Message Icon

Name: ch Bushu
Date: May 7, 2009 at 21:58:22 Pacific
OS: Unix
Subcategory: General
Comment:

Hi All,

I am developing a script which has to execute a set of unix commands. It has to take one argument once.

Means my script is " sample.sh " which executes a list of commands and it has one argument say variable $arg. But this $arg has four values input1, input2 , input3 and input4.

My scripts has to take input1 as the value for $arg first time and execute the list of commands for the script, again it has to take input2 as value for $arg and execute the list of commands for the script and so on...

At the end of completion of the script, it has to generate output for all the values input1, input2, input3 and input4.
Can anyone please help me :(

Thank you…



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: May 8, 2009 at 09:00:22 Pacific
Reply:

I am not certain exactly what you want, but here is my suggestion: Unix numbers command line arguments as $1, $2, etc and the total number of command line arguments is $#.

Consider this sample.sh

#!/bin/ksh

# sample.sh
echo "number of args: $#"

while [ $# -gt 0 ]
do
   echo "$1"
   shift
done
# end script

The shift comand shifts the number of arguments to the left so,$1 is discarded $2 becomes $1, $3 becomes $2, etc and the number of arguments decreases by 1.

The while loop should execute the list of arguments one at a time. Execute:

sample.sh input1 input2 input3 input4

and the output will look like:

number of args: 4
input1
input2
input3
input4


0

Response Number 2
Name: ch Bushu
Date: May 13, 2009 at 22:22:53 Pacific
Reply:

Thanks for you reply... But my scenario is different.
my task is in mq, I have to check for the queues whose current depth is greater than 0 and clear those queues to make the queue depth as zero.
I will use one mq queue depth command which generates a list of queues whose depth is greater than zero. Now I have to use mqclear command to clear all those queues. And all thses should be done in only one script.

Means if there are 3 queues whose depths are greater than 0, my script has to clear the contents of the queue one by one...

I hope you understood my problem..


0

Response Number 3
Name: lankrypt0
Date: May 14, 2009 at 07:04:02 Pacific
Reply:

Can you give a sample of what mq outputs? this does not sound too difficult.


0

Response Number 4
Name: nails
Date: May 14, 2009 at 07:04:34 Pacific
Reply:

Sorry, I have no idea what is "mq" is. I doubt I can help you.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: How to take arguments in unix

How to kill connection in unix www.computing.net/answers/unix/how-to-kill-connection-in-unix/4128.html

Writting To Parallel Port in UNIX www.computing.net/answers/unix/writting-to-parallel-port-in-unix/6284.html

how to span files in unix? www.computing.net/answers/unix/how-to-span-files-in-unix/4954.html