Sponsored Content
Full Discussion: Passing arguments
Top Forums UNIX for Dummies Questions & Answers Passing arguments Post 302454497 by PowerPaul on Saturday 18th of September 2010 02:36:23 PM
Old 09-18-2010
Here you go:
Code:
#!/bin/bash
# short arguments
while getopts  ":a:b:" OPTION
    do
        case $OPTION in
            a)
                PARAM1=$OPTARG
                echo short PARAM1 set to $PARAM1
                ;;
            b)
                PARAM2=$OPTARG
                echo short PARAM2 set to $PARAM2
                ;;
            *)
                break;;
         esac
    done

# long arguments
while [ $# -gt 0 ]
do
    case "$1" in
       -parameter1)
                    PARAM1=$2;
                    echo long PARAM1 set to $PARAM1
                    shift;;
       -parameter2) 
                    PARAM2=$2;
                    echo long PARAM2 set to $PARAM2
                    shift;;
       *)         
                    shift;;
    esac
    shift
done


Code:
./myscript.sh -a "AA;BB;CC" -b "DD;E" -parameter1 "AA;BB;CC" -parameter2 "DD;E"
short PARAM1 set to AA;BB;CC
short PARAM2 set to DD;E
long PARAM1 set to AA;BB;CC
long PARAM2 set to DD;E

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

passing arguments

I'm trying to pass a filename, or all the files in the current directory to the ls command with a script. Unsuccessful so far, here are a few of my attempts: #!/bin/ksh read fname #if (( $# > 0 )); then $fname | ls -l #fi this produces a long listing of all the files in my current... (4 Replies)
Discussion started by: jpprial
4 Replies

2. Shell Programming and Scripting

Passing and using arguments in Scripts.

I am new to scripting in AIX / UNIX. I have a script that runs 4 other scripts and I want to be able to pass in a agrument that I can check before I run the next script to see if the previous script finished with no errors. Can someone send me an example of this as I'm sure it's pretty easy to... (1 Reply)
Discussion started by: David.Vilmain
1 Replies

3. Shell Programming and Scripting

Passing Arguments-Help

Hi, I have a script which adds the user credentials to an ldap server. Im passing the variables as below.. /path/my_script $uname $pwd $environ ${deposit} If i enter some special characters like ';' in $pwd, script returns an error which is set to display if the user enters... (5 Replies)
Discussion started by: Tuxidow
5 Replies

4. Shell Programming and Scripting

passing arguments

Hi I have a script to which I pass multiple arguments, for example lets say the script name is "abc". I run the script like ./abc def /file <directory location> In the above "def" is the first argument and "/file" is the second argument. I expect <directory location> that is passed after... (4 Replies)
Discussion started by: zmfcat1
4 Replies

5. Shell Programming and Scripting

Passing arguments to awk

I have an awk script below which I call using for example awk -f ../../A-Scripts/select-model.awk iterations.txt 16x12 10 I want to be able to use it in a different way like this awk -f ../../A-Scripts/select-model.awk iterations.txt nxz=16x12 iter=10 or awk -f... (1 Reply)
Discussion started by: kristinu
1 Replies

6. Shell Programming and Scripting

Passing arguments to csh

I have noticed this thing using csh when passing arguments Suppose I call a csh script using ../Scripts/plot-model.csh -vmod="npt02-z30.vmod" -R="0/80/0/30" -c="0/4.5" -aspr="1:10" Somehow the " get removed when doing $argv ending up with -vmod=npt02-z30.vmod... (0 Replies)
Discussion started by: kristinu
0 Replies

7. Shell Programming and Scripting

Passing arguments to python

How can I pass arguments to a python script??? (3 Replies)
Discussion started by: kristinu
3 Replies

8. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

9. Shell Programming and Scripting

Passing arguments--Error

Hi, i have a file.txt with data Bangalore Chennai Hyd filename of the script is: new.sh result=`cat file.txt | grep $1` if then echo pass else echo fail fi i am executing the file in the cmd line as "sh new.sh Bangalore" o/p is pass if i give "sh new.sh delhi" o/p is... (6 Replies)
Discussion started by: harsha85
6 Replies

10. Shell Programming and Scripting

Using here document when passing arguments

I have a script test.sh which reads various inputs from a user. #!/bin/ksh read x read y read z echo x: $x y: $y z: $z # read few more things again read a read b echo a: $a b: $b When i run this script as test.sh << EOF 1 2 EOF (3 Replies)
Discussion started by: ariesb2b
3 Replies
PMWEBAPI(3)						     Library Functions Manual						       PMWEBAPI(3)

NAME
PMWEBAPI - introduction to the Performance Metrics Web Application Programming Interface OVERVIEW
The PMWEBAPI interface is a binding of a subset of the PMAPI to the web. It uses HTTP as transport, REST as organizational style for request/parameter encoding (the GET and POST methods are interchangeable), and JSON as response encoding. A context identifier is used as a persistent way to refer to PMAPI contexts across related web requests. These context identifiers expire after a configurable period of disuse. Errors generally result in HTTP-level error responses. CONTEXT CREATION
: pmNewContext To create a new web context identifier, a web client invokes: /pmapi/context?local=ANYTHING Creates a PM_CONTEXT_LOCAL PMAPI context. /pmapi/context?hostname=STRING /pmapi/context?hostspec=STRING Creates a PM_CONTEXT_HOST PMAPI context with the given host name and/or extended specification. If the host specification contains a userid/password combination, then the corresponding pmapi context operations will require HTTP Basic authentication credentials with matching userid/password. /pmapi/context?archivefile=ARCHIVE Creates a PM_CONTEXT_ARCHIVE PMAPI context with the given file name. In addition, the web client may add the parameter &polltimeout=MMMM for a maximum interval (in seconds) between expected accesses to the given context. This value is limited by pmwebd configuration, and is a courtesy to allow pmwebd to free up memory earlier in case of sud- den web application shutdown. If successful, the response from these requests is a JSON document of the form: { "context" : NNNNN } The number (a 32-bit unsigned decimal) is then used in all later operations. PMAPI OPERATIONS
The general form of the requests is as follows: /pmapi/NNNNN/OPERATION where /pmapi is the fixed prefix for all PMWEBAPI operations, NNNNN is a PMWEBAPI context number returned from a context-creation call, or assigned permanently at pmwebd startup, and OPERATION?PARAM1=VALUE2&PARAM2=VALUE2 identifies the operation and its URL-encoded parameters. Some parameters may be optional. METRIC METADATA: pmLookupName, pmLookupDesc, pmTraversePMNS_r The general form of the requests is as follows: /pmapi/NNNNN/_metric Traverse the entire PMNS. /pmapi/NNNNN/_metric?prefix=NAME Traverse the subtree of PMNS with the prefix NAME. The response is a JSON document that provides the metric metadata as an array. For example: { "metrics": [ { "name":"foo.bar", "pmID":PPPP, "indom":DDDD, "type":"32", "sem":"instant", "units":"MHz", "text-oneline":"foo bar", "text-help":"blah blah blah" }, { "name":"foo.bar2", ... } ... ] } Most of the fields are self-explanatory. PPPP the PMID DDDD the instance domain type from pmTypeStr units from pmUnitsStr sem an abbreviation of the metric semantic: PM_SEM_COUNTER "counter" PM_SEM_INSTANT "instant" PM_SEM_DISCRETE "discrete" METRIC VALUE: pmFetch The general form of the requests is as follows: /pmapi/NNNNN/_fetch?names=NAME1,NAME2 Fetch current values for given named metrics. /pmapi/NNNNN/_fetch?pmids=PPPP1,PPPP2 Fetch current values for given PMIDs. The response is a JSON document that provides the values for all requested metrics, for all their instances. { "timestamp": { "s":SEC, "us":USEC }, "values": [ { "pmid":PPPP1, "name":"NAME1", "instances:" [ { "instance":IIII1, "value":VALUE1 } { "instance":IIII2, "value":VALUE2 } ... ] }, { "pmid":PPPP2, "name":"NAME2", ... } ... ] } Most of the fields are self-explanatory. Numeric metric types are represented as JSON integer or floating-point values. Strings are passed verbatim, except that non-ASCII values are replaced with a Unicode 0xFFFD REPLACEMENT CHARACTER code. Event type metrics are not currently supported. INSTANCE DOMAINS METADATA: pmGetInDom, pmNameInDom, pmLookupInDom The general form of the requests is as follows: /pmapi/NNNN/_indom?indom=DDDD List instances of the given instance domain. /pmapi/NNNN/_indom?name=NAME List instances of the instance domain belonging to the named metric. In addition, either query may be suffixed with: &instance=IIII,JJJJ Restrict listings to given instance code numbers. &iname=INAME1,INAME2 Restrict listings to given instance names. The response is a JSON document that provides the metric metadata as an array. For example: { "indom":DDDD, "instances": [ { "instance":IIII, "name":"INAME" } ... ] } INSTANCE PROFILE: pmAddProfile, pmDelProfile /pmapi/NNNN/_profile_reset? These are not currently supported. /pmapi/NNNN/_profile_reset?indom=DDDD These are not currently supported. /pmapi/NNNN/_profile_add?indom=DDDD&instance=IIII,JJJJ These are not currently supported. /pmapi/NNNN/_profile_add?indom=DDDD&iname=IIII,JJJJ These are not currently supported. /pmapi/NNNN/_profile_del?indom=DDDD&instance=JJJJ These are not currently supported. /pmapi/NNNN/_profile_del?indom=DDDD&iname=INAME1,INAME2 These are not currently supported. DERIVED METRICS: pmRegisterDerived /pmapi/NNNNN/_derive?name=NAME&expr=EXPRESSION These are not currently supported. CONTEXT COPY: pmDupContext /pmapi/NNNNN/copy These are not currently supported. CONTEXT CLOSE: pmDestroyContext /pmapi/NNNNN/destroy This is not likely to be supported, as it is destructive and would offer a tempting target to brute-force attackers. Instead, the pmwebd timeout is used to automatically free unused contexts. SEE ALSO
PCPIntro(1), PCPIntro(3), pmwebd(3), and PMAPI(3) Performance Co-Pilot PCP PMWEBAPI(3)
All times are GMT -4. The time now is 01:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy