[Solved]Bash: get positional parameter '$num'

I can't figure out how to do it without using eval:
eval param='$'{$num}
I'm pretty sure it's safe, because num will either be $# or the result of $(( $# - 1 )). But it seems like there should be a non-hackish way to do this.
XYZ: I use diff a lot to compare directories so I made the following function. If I pass -1 to the function, the "Only in <first dir>" messages should be filtered out. Likewise for '-2' and '<second dir>'. '-12' should filter out all 'Only in' messages.
ddif() {
local param exclude diffopts
while (( $# > 2 )); do
if [[ $1 = '-i' ]]; then
diffopts+="--ignore-file-name-case "
shift
elif [[ $1 = '-1' ]]; then
param=$(( $# - 1 ))
eval param='$'{$param}
exclude="Only in ${param//\//.}"
shift
elif [[ $1 = '-2' ]]; then
eval param='$'{$#}
exclude="Only in ${param//\//.}"
shift
elif [[ $1 = '-12' ]]; then
exclude="Only in"
shift
fi
done
if [[ $exclude ]]; then
diff -rq $diffopts "$1" "$2" | sed /"$exclude"/d
else
diff -rq $diffopts "$1" "$2"
fi
$ ddif /mnt/usb/bash /mnt/linux/bash
Only in /mnt/usb/bash/functions/bak: ddif.f.0
Only in /mnt/usb/bash/functions: ddif.f
Files /mnt/usb/bash/functions/test.f and /mnt/linux/bash/functions/test.f differ
Only in /mnt/linux/bash/: root-bash_aliases
Only in /mnt/linux/bash/: root-bashrc
$ ddif -1 /mnt/usb/bash /mnt/linux/bash
Files /mnt/usb/bash/functions/test.f and /mnt/linux/bash/functions/test.f differ
Only in /mnt/linux/bash/: root-bash_aliases
Only in /mnt/linux/bash/: root-bashrc
$ ddif -2 /mnt/usb/bash /mnt/linux/bash
Only in /mnt/usb/bash/functions/bak: ddif.f.0
Only in /mnt/usb/bash/functions: ddif.f
Files /mnt/usb/bash/functions/test.f and /mnt/linux/bash/functions/test.f differ
Last edited by alphaniner (2014-04-18 17:34:41)

Thanks, I can definitely work with that. Here's the updated function:
ddif() {
local exclude diffopts
while (( $# > 2 )); do
if [[ $1 = '-i' ]]; then
diffopts+="--ignore-file-name-case "
shift
elif [[ $1 = '-1' ]]; then
exclude="Only in ${@:$(( $# - 1 )):1}"
shift
elif [[ $1 = '-2' ]]; then
exclude="Only in ${@:$#:1}"
shift
elif [[ $1 = '-12' ]]; then
exclude="Only in"
shift
fi
done
if [[ $exclude ]]; then
diff -rq $diffopts "$1" "$2" | sed /"${exclude//\//.}"/d
else
diff -rq $diffopts "$1" "$2"
fi
Anyway, I just posted the function for context. I'm not necessarily looking for alternatives or anything.
Last edited by alphaniner (2014-04-18 17:34:05)

Similar Messages

  • UTL MAIL a positional parameter association may not follow a named associat

    I am trying to sale 2 emails, I got the code like this
    {code|
    utl_mail.send(sender => '[email protected]',
    recipients => '[email protected]','[email protected]',
    subject => 'Banner Duplicate Report '||trunc(sysdate)||' Process for Managing Known Duplicate Reports',
    message => 'You are about to receive a report with possible duplicates in the Database, THIS IS A TEST' ||chr(10)||chr(13)||
    I am getting this error...
    PLS-00312 a positional parameter association may not follow a named association....
    I try to separate the email by ; does not work either...
    Thank you 
    Ps I changed the real emails by xxxx                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    842471 wrote:
    I am getting this error...
    PLS-00312 a positional parameter association may not follow a named association.... The reason for the error. You are writing this:
    utl_mail.send(
      sender     =>  '[email protected]', 
      recipients => '[email protected]',
      '[email protected]',
       subject    => 'Banner Duplicate Report '||trunc(sysdate)||' Process for Managing Known Duplicate Reports',
      ..etc..
    );The compiler/parser sees that you are specifying the parameter name followed by the value. So:
    This is fine:
    sender     =>  '[email protected]',
    So is this:
    recipients => '[email protected]',
    But what is this? Parameters are separated with commas. Where is the parameter name?
    +'[email protected]',+
    PL/SQL can either support the call where you do not specify the parameter name. For example: (using positional parameters)
    DBMS_OUTPUT.put_line( 'hello world' );
    Or support where you do specify the parameter names. For example: (using named parameters)
    DBMS_OUTPUT.put_line( a => 'hello world' );
    But you cannot mix these two methods as you have done. Thus the error message stating exactly this.
    The recipients parameter is scalar value. It expects a single string value. Not multiples values.
    The string itself can contain a comma delimited list of recipients. E.g.
    recipients => '[email protected],[email protected],[email protected]',

  • How to get radiobutton & parameter side by side?

    Hi abapers,
    Could any one tell me how to get radiobutton & parameter side by side.Iam trying to get in the single line....
    But i could not.
    thanks
    Kaki

    Hello Kaki,
    The code given by Rainer should give you the idea (to use   SELECTION-SCREEN BEGIN OF LINE.) If you need a parameters on the same line, then you just need to do something like this -
    SELECTION-SCREEN BEGIN OF BLOCK test WITH FRAME TITLE frametxt.
      SELECTION-SCREEN BEGIN OF LINE.
        PARAMETERS: Option1 RADIOBUTTON GROUP xyz.
        SELECTION-SCREEN POSITION 10.
        PARAMETERS: P_TEST1 TYPE I.
      SELECTION-SCREEN END OF LINE.
      SELECTION-SCREEN BEGIN OF LINE.
        PARAMETERS: Option2 RADIOBUTTON GROUP xyz.
        SELECTION-SCREEN POSITION 10.
        PARAMETERS: P_TEST2 TYPE I.
      SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK test.
    Regards,
    Anand Mandalika.

  • Positional parameter

    When I run my form and after starting the JAVA Applet I get this Error message
    FRM-90928 Positional parameter after key in command line. What does that mean?

    My bet is that your fmx is located in a directory with space in its name like "my document". Try saving the fmb and fmx in c:\
    and see if it still happens.
    If you still have problems please post the URL that is invoked to run your form.

  • Exchange 2010 - New-Mailbox - A positional parameter cannot be found that accepts argument '-PrimarySmtpAddress'.

    Hi,
    I am currently writing a powershell script that utilizes the new-mailbox command of EMS to create a shared mailbox.
    I am connecting to EMS via a remote PSSession object.
    When I try and specify an alternative SMTP address via the -PrimarySmtpAddress paramater I get the error
    " A positional parameter cannot be found that accepts argument '-PrimarySmtpAddress'.
    I have confirmed that the version of Exchange 2010 installed on the server should have this parameter - Version 14.3 (Build 123.4)
    An example command :-
    New-Mailbox -Shared -Name "SharedMailbox_test" -Alias "testsharedmailbox" -DisplayName "SharedMailbox_test" -UserPrincipalName "[email protected]" -OrganizationalUnit "OU=Mailboxes,OU=Accounts,DC=domain,DC=com"
    -Database "DB1" -PrimarySmtpAddress "[email protected]" -force
    Has anyone else experienced this behavior?
    Steve.
    Just a good old boy, never meaning no harm

    Hi Rich,
    That was my initial thought too, so I triple-checked my command to see if it was a simple syntax error - it wasn't.
    On further investigation I compared the list of parameters available in a DEV EMS session (on where I know the command works) against the one in PROD where the problem occurs.  Both sessions are running the same version of EMS.
    I ran the following to get a list of parameter names in both sessions :-
    $a = gcm New-Mailbox
    $a.Parameters.Keys | sort
    Here's the results :-
    DEV EMS (working)
    Prod EMS (missing)
    AccountDisabled
    ActiveSyncMailboxPolicy
    AddressBookPolicy
    Alias
    Alias
    Arbitration
    ArbitrationMailbox
    Archive
    ArchiveDatabase
    ArchiveDomain
    AsJob
    AsJob
    Confirm
    Confirm
    Database
    Database
    Debug
    Debug
    Discovery
    DisplayName
    DisplayName
    DomainController
    DomainController
    Equipment
    Equipment
    ErrorAction
    ErrorAction
    ErrorVariable
    ErrorVariable
    FirstName
    FirstName
    Force
    Force
    ImmutableId
    Initials
    Initials
    LastName
    LastName
    LinkedCredential
    LinkedDomainController
    LinkedMasterAccount
    ManagedFolderMailboxPolicy
    ManagedFolderMailboxPolicyAllowed
    ModeratedBy
    ModerationEnabled
    Name
    Name
    Office
    OrganizationalUnit
    OrganizationalUnit
    OutBuffer
    OutBuffer
    OutVariable
    OutVariable
    Password
    Phone
    PrimarySmtpAddress
    RemoteArchive
    RemotePowerShellEnabled
    ResetPasswordOnNextLogon
    ResetPasswordOnNextLogon
    ResourceCapacity
    RetentionPolicy
    RoleAssignmentPolicy
    Room
    Room
    SamAccountName
    SamAccountName
    SendModerationNotifications
    Shared
    Shared
    SharingPolicy
    ThrottlingPolicy
    UserPrincipalName
    UserPrincipalName
    Verbose
    Verbose
    WarningAction
    WarningAction
    WarningVariable
    WarningVariable
    WhatIf
    WhatIf
    It might be a permissions-based issue, but I don't own either EMS session so can't test personally.
    I will keep investigating and update here once I have some further information.
    Regards,
    Steve.
    Just a good old boy, never meaning no harm

  • Powershell date range positional parameter error

    I am trying to export emails sent to a particular email address in a specific date range.  I can run the command and it works fine without the date range, but when I try to include it it errors out.  Any help appreciated.
    Working command without date range:
    Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery “To:’[email protected]’” -TargetMailbox "SearchResults" -TargetFolder Export
    And repeat it using “From” instead of “To”
    When I try to add a date range though like this:
    Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery “To:’[email protected]’” -ContentFilter {(Received -gt '08/15/2014') -and (Received -lt '02/18/2015')} -TargetMailbox "SearchResults" -TargetFolder Export
    I get the below error listing:
    A positional parameter cannot be found that accepts argument '(Received -gt '08/15/2014') -and (Received -lt '02/18/201
    5')'.
        + CategoryInfo          : InvalidArgument: (:) [Search-Mailbox], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Search-Mailbox
    Invoke-Command : Cannot write input as there are no more running pipelines
    At C:\Users\exservice\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\kc-exchange.us.org\kc-exchange.us.org.p
    sm1:43760 char:29
    +             $scriptCmd = { & <<<<  $script:InvokeCommand `
        + CategoryInfo          : InvalidOperation: (:) [Invoke-Command], PSInvalidOperationException
        + FullyQualifiedErrorId : NoMoreInputWrite,Microsoft.PowerShell.Commands.InvokeCommandCommand

    Get-Mailbox -ResultSize Unlimited |
    Search-Mailbox -SearchQuery "Received:> $('2014-08-15') AND Received:< $('2015-02-18') AND To:'[email protected]'" -TargetMailbox "SearchResults" -TargetFolder Export

  • Restore-SPSite : A positional parameter cannot be found that accepts argument '$null'.

    Restore-SPSite : A positional parameter cannot be found that accepts argument '$null'.
    At line:1 char:15
    + Restore-SPSite <<<<  http://weekly-sn-cas.statoil.com/sites/ts-17067/ -Path C:\backup\ts-47438(1).bak
        + CategoryInfo          : InvalidArgument: (:) [Restore-SPSite], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.SharePoint.PowerShell.SPCmdletRestoreSite
    plz give me solution above this
    ravi sharepoint

    Hello,
    can you provide the command you execute?
    Best regards, Christopher.
    Blog |
    Mail
    Please remember to click "Mark As Answer" if a post solves your problem or
    "Vote As Helpful" if it was useful.
    Why mark as answer?

  • How to get the parameter from Java Script into the Parameter crystal Report

    Hi All,
    Crystal Report is integrated with Oracle 10g. I created the base SQL query for col1, col2, col3 and col4. Java Script pass parameter value (185) to Col1.
    My question is how to create crystal report to make Col1 as parameter and how to get the parameter value 185(Col1) from Java Script. Is there any additional code I need to include in the crystal report?
    FYI.
    Java script sends the right parameter value.There is no issue in java script.
    This is an automatic scheduled process when batch runs, Java script should pass the parameter value and the crystal report should get the value and produce the output report.

    Not sure if this is an application question or if you are trying to hook into Crystal Reports parameter UI? If the later then no option other than report design. If an application then I can move this to the Java Forums.
    If you are asking how to alter the parameters I suggest you remove the Java reference and post a new question so it's not confusing the issue.
    Please clarify?

  • Can viewObject get a parameter from sessionScope to binding variable?

    hello,
    using Jdev11g ADF Fusion application
    Can viewObject get a parameter from sessionScope and assign into binding variable ? without using executeWithParameter
    Thanks
    greenApple

    A. Safwat,
    As I said before, I was not trying to be offensive, but simply to explain some of the shortcomings of one solution over another. One of the reasons people give such short answers is that many questions (including this one) have been asked and answered many many many times before on the forum. As to my reasons:
    1). Overkill - overkill because you are writing code to do what the framework already provides for you.
    2). Not bind-variable friendly - you are gluing in literals into a SQL statement. That means that Oracle will have to hard parse the query for each new value of the filter clause, yielding to poor performance, particularly in a multiuser environment. It should ideally be done using bind variables.
    3). Insecure (think about what happens if you put "'xyz' or 1=1" into the filterValue there) - not using bind variables is a security hole. Think through what happens if a filter criteria comes through like the one I mentioned.
    4). Inflexible - because you are overriding executeQueryForCollection, this VO becomes inflexible and can only be used in this particular place. Using the declarative approach outlined by Timo is more flexible
    5). Bad (ok, that's my opinion there) - OK, perhaps this was a bit offensive ;)
    Please don't take a critique of a post as offensive, as I assure you it was not intended to be in that spirit. As I mentioned, I greatly appreciate when people point out issues/problems/etc with my ideas, as that is the best way for me to learn. I have in the past written applications that were not bind-variable friendly, and I learned the downsides the hard way (system was horribly non-performant) - I wish someone had reviewed my approach and told me "bad idea" before the application made it into production.
    Respectfully,
    John

  • How to get a parameter without name in JSP?

    hi everyone, My question is how to get a parameter without name in JSP? I have two pages, 1.html and 2.jsp.
    in 1.html, I embeds some Javascript codes in HTML contents like below ( changed < to ( , > to )):
    function toSubWin( obj )
    window.open('test.jsp?'+obj.firstChild.toString(),'sw');
    (a onClick='toSubWin(this)'style="background:green")focus(/a)
    How can I get the parameter in 2.jsp?
    THANK YOU IN ADVANCE!!

    Does obj.firstChild.toString() evaluate to a "name=value" type of String ?
    Or better what does obj.firstChild.toString(),'sw' evaluate to ? It has to end up in a name=value format, else its just gibberish appended to the url.
    In the jsp, you have to obviously know the name to get the parameter. There's a getParameterNames() method which returns you a Collection of parameter names as Strings, you could probably use that to retrieve the param values.
    Then there's a getParameterMap() method which returns an immutable Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.
    However to what ends you employ them in a program which doesnt know its inputs is a different story.
    cheers,
    ram.

  • How can I get a parameter back into a servlet invoked from an IMG tag ?

    I'm using a servlet to create several graphical plots per JSP i.e. per HTML page. Each graph is supposed to be different, according to a parameter which I want to pass back from my JSP. I'm getting several plots but they're all the same!
    I've tried setting an attribute in the session object before each IMG SRC= , but all I get is each plot the same! In fact, my debugging efforts show that the servlet is only called once despite 3 calls, each with a different session parameter value. I'm not sure the session parameter values are getting used properly.
    I just can't find a way of getting a parameter back into my servlet which is invoked from the IMG tag (i.e. SRC= "servlet name").
    Can anyone tell me the best way to pass a parameter back into a servlet which is invoked from an IMG tag? Can the request object be used? I can't, at the moment, see how it could be used?
    I'll certainly be very grateful if anyone can help with this - could even be useful for others as well!

    You said that, "by moving a copy of Mobile Docs back to the Library, from which I had moved it, my documents reapperared in Cloud." That says that you actually moved it. Obviously, I can't tell exactly what you did, but it sounds like you may have thought you were just putting it in the sidebar, but you actually put it somewhere else. The sidebar is not a location to put things, just a way to create a quick shortcut to access a file or folder, so you can't put things "back" from there.

  • I put my card num in here so I could buy sum things wen I didn't have the money but I don't have any money on my card so I went n bought a $25 card n now it won't work cyz I can't get my 1 card num off here it won't let me.. How do I get that card num of.

    I put my card num in here so I could buy sum things wen I didn't have the money but I don't have any money on my card so I went n bought a $25 card n now it won't work cyz I can't get my 1 card num off here it won't let me.. How do I get that card num off!!

    i the top right corner of the iTunes store click on your account, log in and go to billing info. Hope this helps

  • How to get Position from EmployeeInfo in DIAPI

    I am using DIAPI(JCO) for SAP B1. According to one or my reuirement i am in need of Position from the EmployeesInfo. But there  seems no option or method for getting position from that. Can anyone guide me how to get that from EmployeesInfo ? Any help is appreciated..

    Looking at the DI API properties vs. DB fields mapping documentation in the SAP Business One developer area (https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/c5f5dbcc-0a01-0010-5d82-f25f2bee715e)
    it seems that this field is not exposed (yet).
    I.e. you could only run a SQL statement to get this information.
    Sorry,
    Frank

  • Possible to get application parameter in value help

    Hello colleagues,
    we developed a value help for business partner to use it in an wda-component . in this value help only those business partner should get supplied where the user has a relationship to . to make it really difficult we can not use the backend user (crm) but the portal user . in the component which uses the value help we achieve to get the user via application parameter from the containing iview but as soon as the user calls the value help this context is lost and we can no longer use the application parameter (which is in fact "out" of the iview) to retrieve the user of the application and therefore get a dump.
    Is there a possibility who to get application parameter of a component in a value help called by this component ?
    Thanks in advance
    Michael

    Hi,
    PLease refer to this link
    http://help.sap.com/saphelp_nw70/helpdata/en/88/266a3e54a2e946e10000000a114084/frameset.htm
    You can enter parameter values for certain screen fields for displaying a SAP transaction here.
    This field is optional.
    The parameter values are specified with the following syntax:
    <Screen_field1>=<Parameter1>
    &<Screen_field2>=<Parameter2>
    Thanks
    Pankaj

  • It is possible to get giving parameter field name in function module

    i have one question like below .
    at main report .
    call funciton Fm1
      exporting
         var1 = W_A
         var2 = W_B
    at function module i want to get  giving  parameter field name, in here  value was  "W_A" and "W_B"  .
    plz give me some hints or any advise .

    Only a hint:
    If you have a fm with an unspecified parameter like
    FUNCTION ZTESTBABLFM.
    *"*"Lokale Schnittstelle:
    *"  IMPORTING
    *"     REFERENCE(INPUT)
    type-pools: sydes.
    data: fieldinfo type SYDES_DESC.
      describe field input into fieldinfo.
    ENDFUNCTION.
    you can get some information from DESCRIBE FIELD  either using INTO as above or with other options as LENGTH, TYPE ...

Maybe you are looking for

  • PSE-11 will not open.

    PSE-11 will not open.  Says MSVCP110.dll is missing.  But when I look in program files, it is there.

  • Delivery Confirmation

    Hi Experts, I have a problem, we normally purchase various material from xxx country from different vendors, and we have one representative in that country, who confirms us when the vendors will send the material, but we want he should enter order ac

  • Transformation in matching mode in data manager

    Hi , Can anyone tell me when should we do trasformation in data manager (matching mode)? How can we do it? Can any one provide me example? Thanks

  • Lightroom 5.7 will not import images from my nikon cameras

    Lightroom 5.7 will not import my Nikon DSLR images although iPhoto will on an iMac

  • Dust/Dirt/Dark patch behind the screen?!

    I am certain that this has appeared today, and seems to be a small dark patch of something behind the screen. It is not a dead or stuck pixel but a small dark patch almost in the centre of the screen. I have tried cleaning the screen with the provide