Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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…

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 scriptThe 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

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

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |