Sponsored Content
Top Forums Shell Programming and Scripting How to iterate a function untill last argument with any order of input? Post 303020466 by Priya Amaresh on Friday 20th of July 2018 04:24:37 AM
Old 07-20-2018
How to iterate a function untill last argument with any order of input?

HI

I need to get the function "kick" to get executed in any way the parameters are passed in to the function. The parameters are first stored in a dictionary
Code:
        self.otherlist = {}
        print self.otherlist
        self.populateTestList(self.system_type)
        print "########################################################"
        for machine, market in self.otherlist.items():
            print [(v if isinstance(v, basestring) else v.keys()[0]) for v in market]
        print "########################################################"

1) I am passing arguments i) vegetables ii) fruits to the function kick
Code:
    def kick(self,system,market):
        if isinstance(market, dict):
            for key, val in market.items():

                if re.search('fruits', key, re.M|re.I):
                    fus = ""
                    for count, fus_area in enumerate(val.get('Fus_Area')):
                        if count == 0:
                            fus = fus_area.lower()
                        else:
                            fus = fus + "," + fus_area.lower()

                    cmd = "python %ssetup.py %s %s %s" % \
                        (cur_path, host, fus, self.build)
                    rc = self.exec_proc(cmd)

                elif re.search("flowers",market, re.M|re.I):
                    cmd = "python %sdump1.sh %s %s %s" % \
                        (cur_path, host, system, self.build)
                    rc = self.exec_proc(cmd)

        else:
            if re.search("vegetable",market):

                       cmd = "python %sguestlist.py \
                        %s --log-number " % \
                        (self.jid)
                    rc = self.exec_proc(cmd)

                else:
                    cmd = "piral Config \
                    %s" % \(system)
                    rc = self.exec_proc(cmd)

self.kick(system,market)

The output expected is as follows:

When I pass first argument "vegetable" second argument "fruit" the loop flows to "else" condition and gets executed only for second argument "fruit" then it should pass to first argument and get "vegetable" parameter also executed.

But here with this code when I pass first argument "vegetable" second argument "fruit" the loop flows to "else" condition and gets executed only for second argument "fruit" and the flow ends.

Please help to get all arguments getting executed with any order (vegetable, fruit) or (fruit, vegetable) provided as input.

Thanks in advance
Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Passing Argument to Function

May i know how to pass an argument to a function in a shell script? Sorry, i din stated that it is in a shell script in my previous post. Means: checkStatus() { ........... } read status; I wanna use the status in the function checkstatus, how... (2 Replies)
Discussion started by: AkumaTay
2 Replies

2. Programming

How do I input an argument in the main?

----------C program----------------------------- include <stdio.h> int main( int argc, char *argv ) { int i; for( i=0; i<argc; i++ ) printf("%\n", argv); return 0; } I wrote the C program above 'print.c'. Then, I compiled. (gcc -o print.o print.c)... (2 Replies)
Discussion started by: yhosun
2 Replies

3. UNIX for Dummies Questions & Answers

Pass argument to function

Hi, Can someone please explain to me how I can get a function to recognize a file given as an argument to a script. Suppose the script has the argument as follows: sh script file and the function is as follows: function display_file () { cat $1 } and it s then called #main program... (1 Reply)
Discussion started by: Knotty
1 Replies

4. Shell Programming and Scripting

Passing more than one argument in a function

Hi All, Calling a function with one argument and storing the return value in a shell script is as below:( so far I know) value="`fun_1 "argument1"`" Its working perfectly for me. Can u help me with passing more than one argument and storing the return value Thnaks in advance JS (1 Reply)
Discussion started by: jisha
1 Replies

5. Shell Programming and Scripting

pass function as argument to a function

I have the following code : function1 () { print "January" } function2() { case $1 in January) print "Dzisiaj mamy styczen" ;; *) ;; } main() { (1 Reply)
Discussion started by: presul
1 Replies

6. Shell Programming and Scripting

Split function input and output order

Dear Forum I'm Trying to use split function to split a string, but the output is not as the same order as of the string, please see simple example echo " " | nawk -v var="First;Second;Third;Fourth" ' BEGIN {split(var, arr,";") for(i in arr){print arr }}' The output is Second Third... (6 Replies)
Discussion started by: yahyaaa
6 Replies

7. Shell Programming and Scripting

function terminating if i give input as space or no input and enter

HI i have written a script to ask input from the user. this script should promote the user for y/n input. if user enters anyother input then y/n the script promotes him again. this below code is working fine for all the cases. except for space and enter " if i give space and enter it is... (2 Replies)
Discussion started by: BHASKARREDDY006
2 Replies

8. Shell Programming and Scripting

passing argument from one function to another

Hi all, In the given script code . I want to pass the maximum value that variable "i" will have in function DivideJobs () to variable $max of function SubmitCondorJob(). Any help? Thanks #!/bin/bash ... (55 Replies)
Discussion started by: nrjrasaxena
55 Replies

9. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

10. UNIX for Beginners Questions & Answers

How to iterate Grep via all patterns provided in an input file?

When I use the following grep command with options -F and -f, its just displaying the text related to only the last pattern. Command: $ grep -f pattern_file.txt input_file.txt Output: doc-C2-16354 Even the following command yields the same output: Command: $ grep -Ff pattern_file.txt... (6 Replies)
Discussion started by: nsai
6 Replies
uadmin(1M)																uadmin(1M)

NAME
uadmin - administrative control SYNOPSIS
/usr/sbin/uadmin cmd fcn [mdep] /sbin/uadmin cmd fcn [mdep] The uadmin command provides control for basic administrative functions. This command is tightly coupled to the system administration proce- dures and is not intended for general use. It may be invoked only by the super-user. Both the cmd (command) and fcn (function) arguments are converted to integers and passed to the uadmin system call. The optional mdep (machine dependent) argument is only available for the cmd values of 1 (A_REBOOT), 2 (A_SHUTDOWN), or 5 (A_DUMP). For any other cmd value, no mdep command-line argument is allowed. When passing an mdep value that contains whitespaces, the string must be grouped together as a single argument enclosed within quotes, for example: uadmin 1 1 "-s kernel/unix" See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ uadmin(2), attributes(5) On systems, shutting down the system by means of uadmin does not update the boot archive. Avoid using this command after manual editing of files such as /etc/system or driver.conf(4). 11 Apr 2005 uadmin(1M)
All times are GMT -4. The time now is 06:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy