Passing arguments to case

Hi, I am trying to run this script as follows;
avplaylist -a Music/artist/
or
avplaylist -v Videos/tv_show/
and have it create a sorted playlist for me. It works if I make one function for audio and one for video but not this way, what am I doing wrong?
#!/bin/bash
caser() {
while read i; do
case "$i" in
"$1") echo "$i" >> "$3" ;;
esac
done < <(find "$2" -name "*" | sort)
lister() {
if [ -e "$1" ]; then
cat "$1" | wc -l
else
echo 0
fi
case "$1" in
-v)
caser "*.mov|*.avi|*.mp4|*.flv|*.wmv|*.MTS|*.mpeg|*.mpg|*.mkv" "$2" "videoplaylist"
lister "videoplaylist"
-a)
caser "*.wav|*.aif|*.aiff|*.wma|*.mp3|*.ac3|*.flac|*.ogg" "$2" "audioplaylist"
lister "audioplaylist"
esac
Thanks in advance!

roygbiv, the $1,$2..$n are not reserved for the command-line when you call functions as above, at least that is my understanding.
The problem seems to be when I try to pass "*.mov|*.avi|*.mp4|*.flv|*.wmv|*.MTS|*.mpeg|*.mpg|*.mkv" as an argument, since this version works:
#!/bin/bash
vcaser() {
while read i; do
case "$i" in
*.mov|*.avi|*.mp4|*.flv|*.wmv|*.MTS|*.mpeg|*.mpg|*.mkv) echo "$i" >> "$2" ;;
esac
done < <(find "$1" -name "*" | sort)
acaser() {
while read i; do
case "$i" in
*.wav|*.aif|*.aiff|*.wma|*.mp3|*.ac3|*.flac|*.ogg) echo "$i" >> "$2" ;;
esac
done < <(find "$1" -name "*" | sort)
lister() {
if [ -e "$1" ]; then
cat "$1" | wc -l
else
echo 0
fi
case "$1" in
-v)
vcaser "$2" "videoplaylist"
lister "videoplaylist"
-a)
acaser "$2" "audioplaylist"
lister "audioplaylist"
esac
Passing of $1,$2..$n variables works just fine in this version!

Similar Messages

  • How can we pass argument to static block of code????

    hi ,
    My question is we can use static initialization block for having functionality like constructors for initializing static variable ,but we cannot pass arguments to static initialization block then how can I create functionality like parametrized constructors.Whats the alternative shall I use a static method to perform this functionality,since all methods in given class are static and
    there is no need of creating instance of class.

    jduprez wrote:
    Hello Jussi,Salut Jérôme
    That's probably a more maintenable design.
    However what do you base your remark on - I'm struck by the word obviously?
    Is there some design principle from which this advice so naturally ensues that it is obvious ?Yes I read my posting later on and thought about changing it, since it's not necessarily an obvious solution. I was making assumptions that I didn't clarify from the OP.
    In the OP's case, the "state" on which those methods operate is apparently fixed, presumably at the beginning of the program, so what's wrong with all this staticness?
    I can list:
    - threading issues (a non-issue after some initialization phase), that you wouldn't have with immutable instances
    - harder unit-testing (that's not an OO design problem, more a methodology problem)
    - mix and confusion between static and non-static state if the class ever happens to have both, in future maintenance. All good points, I see all-static classes as a "code smell" and especially in this case when there's parametrization involved.
    Now we just need to have the OP explain his situation a bit better.

  • Passing arguments in Visitor Pattern

    Does anybody have a nice solution to passing arguments in Visitor pattern?
    The Visitor pattern is used to process an object structure (such as an abstract syntax tree) in many different ways without cluttering definitions of the objects with methods needed for all different kinds of processing. Instead, each object has only one method, "void accept(Visitor v)". The method calls back a method in the Visitor that is appropriate for the object. Different kinds of processing use different Visitors, each with its own set of object-processing methods.
    My problem is that I need to pass arguments or receive results from the object-processing methods, different for different kinds of processing.
    One solution is to have many "accept" methods with different signatures. This beats the idea that we do not need to modify definitions of the objects if we want to introduce new kind of processing.
    Another is to provide "accept" with an Object result and a sufficient number of Object arguments, to be used as necessary by different Visitors. It results in clumsy and unreadable code. Detestable.
    Alternatively, one could provide fields in the objects to pass the information when needed. This frees the invocations of "accept" from dummy arguments/results, but does not seem nice.
    One can also forget all about Visitor pattern, and let the processing method test the object class using "instanceof" and call the right method. But this is a pure blasphemy against everything called OO.
    Is there any better way that I am too blind to see?

    Sounds to me like you've got a case of combining different concerns into the same design. I think you're looking at multiple problems, all of which require you to process an object structure.
    I'd make a general framework for processing my structure, and then use a specific interface for each problem. I would avoid re-using the Visitor pattern for multiple concerns as it leads to exactly the problems you're facing.
    If you're dead-set on using the Visitor; how about having a mediator or adapter between the visited class and the Visitor that deals with the specifics of each invocation?
    Personally, I think the Visitor pattern violates basic encapsulation and polymorphism - but that's just my opinion. I try to avoid using it unless I'm stuck with NO other solution.
    Good luck.

  • Passing arguments to Managed Server ServerStart when using Node Manager

    Below is the procedure to pass arguments to Managed Server serverstart tab when using Node Manager to start and stop the Managed Server instance
    For passing the JVM arguments we will have to use "-server" which is hotspot and then pass the arguments
    for eg: "-server -Xms2048m -Xmx2048m -verbosegc"
    For adding jar's to the classpath you will have to add weblogic.jar and weblogic_sp.jar from WL_HOME/server/lib directory as well along with the custom jar (In some cases we can ignore weblogic_sp.jar, just adding weblogic.jar will do).
    for eg: "\home\user\debug.jar;\home\user\bea\wlserver_10.3\server\lib\weblogic.jar;\home\user\bea\wlserver_10.3\server\lib\weblogic_sp.jar;"
    - - Tarun

    Hi,
    To me, if you don't wanna use the NodeManager, you won't be able to start your managed servers with WLST.
    I guess the only ways are :
    * through the console / WLST using the NodeManager
    * using the startManagedWebLogic.[cmd/sh]
    Regards

  • Passing arguments to the jsx file from command line

    Thanks for taking my question.
    I am using the following to be able to run my script from the command line.In case you were wondering on why i would be doing this- i would need to invoke the javascript from a server side code(like java,php etc. in my case it is java)
    "c:\Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit\ExtendScript Toolkit.exe" "c:\path to script\myscript.jsx"
    Anyways, i have been successful in running the myscript.jsx from the command line but i am not able to figure out how i could pass arguments to "myscript.jsx" from the command line, and be able to refer to these arguments within the script.
    I have tried the following
    "c:\Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit\ExtendScript Toolkit.exe" "c:\path to script\myscript.jsx" "argument1" "argument2"
    and tried to refer these arguments within the script using arguments[0] and arguments[1] . But looks like this does not work.
    Any thoughts?????

    To run JavaScript from the prompt using ExtendScript Toolkit 1.0.3 or 2.0.2 you need to do the following:
    Add the line #target indesign to the top of your script otherwise ESTK will open without executing the script. Example:
    #target indesign
    //MakeDocumentWithParameters.jsx
    //An InDesign CS2 JavaScript
    //Shows how to use the parameters of the document.open method.
    //The first parameter (showingWindow) controls the visibility of the
    //document. Hidden documents are not minimized, and will not appear until
    //you add a new window to the document. The second parameter (documentPreset)
    //specifies the document preset to use. The following line assumes that
    //you have a document preset named "Flyer" on your system.
    var myDocument = app.documents.add(true, app.documentPresets.item("Flyer"));
    //SaveDocumentAs.jsx
    //An InDesign CS2 JavaScript
    //If the active document has not been saved (ever), save it.
    if(app.activeDocument.saved == false){
    //If you do not provide a file name, InDesign will display the Save dialog box.
    app.activeDocument.save(new File("/c/temp/myTestDocument.indd"));
    Ensure Indesign is open. Execute the following command:
    "C:\Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit\ExtendScript Toolkit.exe" -run "[path to script]\script.jsx"
    For example:
    "C:\Program Files\Adobe\Adobe Utilities\ExtendScript Toolkit\ExtendScript Toolkit.exe" -run "C:\Program Files\Adobe\Adobe InDesign CS2\Presets\Scripts\test.jsx"
    This command can be easily called from Java or any other third party application of your choice.
    It took me a while to find this information, so I thought I'd share it with everyone.
    Good luck!

  • How to run a java class from a shell script with passing arguments

    hi,
    I have a jar with all the required classes. I was using ant to run the classes i needed.
    But now i want to use a shell script to run the class, also the class accepts some arguments so when script is run it should accept arguments.
    So can any one tell me how to set class paths, jar location and call the required class from shell script or batch file with passing arguments to it.
    Thanks in advance.

    Let's say that the order of arguments is as below
    1. Jar file name
    2. Classpath
    Your shell script would look like this
    java -cp $CLASSPATH:$2 -jar $1 I am assuming that your jar file has the required main-class entry in its manifest. Note that $1...$9 represent the arguments to this shell script.
    The same goes for a batch file
    java -cp %CLASSPATH%;%2 -jar %1

  • How to pass argument to the Java Plugin JVM w/o using the Control Panel?

    I want to deploy an applet to be loaded by the Java Plug In
    and fix some settings of its Java Virtual Machine.
    The JPI Control Panel offers two ways to pass arguments to the JVM,
    none satisfactory.
    1. while interactive via the Control Panel Window.
    This cannot be a solution for a deployed applet.
    or
    2. by editing the system generated file that stores
    the settings of the Plugin Control Panel, using a property
    named javaplugin.jre.params.
    The problem with this method is that if forces to access
    and edit this property file which is stored at various locations
    depending the client platform. Then, it may collide with other
    settings for other applets.
    Is there a way to pass the arguments to the JVM
    from within the html file?
    Has anyone found a solution to this question?
    JPS

    I am interested in this issue as well.
    Did anyone find a reliable way to specify the runtime parameters that should be used by the Java Plug-in in order to execute a given Java applet?
    I believe a good place to specify these runtime parameters would be the applet's JAR manifest: only digitally signed applets should be able to set the desired runtime parameters...
    Any comments / suggestion would be greatly appreciated.
    Regards,
    Marco.

  • How to pass argument in manifest file

    Hi,
    I want to pass argument to main class in jar. Is there any option in manifest file.

    Hmm..
    Seems that my sentence above isn't so correct.
    It possible to add custom attribute: value pairs into manifest file and
    read it later from Java class.
    Here is code sample:
    public class ManifestTest {
        public static void main(String[] args) {
            try {
                java.util.jar.JarFile jar = new java.util.jar.JarFile(System.getProperty("java.class.path"));
                for (java.util.Iterator it = jar.getManifest().getMainAttributes().keySet().iterator();it.hasNext();) {
                    Object curKey = it.next();
                    System.out.println("key: " + curKey + ", value: " + jar.getManifest().getMainAttributes().get(curKey));
            } catch (Throwable t) {
                System.out.println("exception occured: " + t);
    }

  • How can I pass arguments to a TestStand sequence with LabWindows 6 ?

    Hi
    I have created sequences in a TestStand file.
    I want to program a sequence with Labwindows 6 which would call all these existing sequences (containing parameters).
    I don't have any problems to create the steps "SequenceCall" but i don't know how to pass arguments to the sequences with the TS API.
    I have used the look-up strings "TS.SData.SFPath", "TS.SData.SeqName", "TS.SData.ThreadOpt" to program the sequence file / sequence and the multithread option. But now how to program the arguments passing ? I think there is something with the lookup string "ST.SData.ActualArgs"...
    Thank u very much for any help

    I'm not sure if you want to pass values from TestStand to LabWindows or if you want to pass values in TestStand from a sequence call step to a called sequence.
    To get TestStand variables from LabWIndows, use the following function:
    tsErrChk (TS_PropertyGetValNumber(testData->seqContextCVI, &errorInfo, "Locals.StartPoint", 0, &dStartPt));
    iStartPt = (int)dStartPt;
    The TS_PropertyGetValNumber gets the TestStand variable Locals.StartPoint and puts it into the LabWindows variable called dStartPoint. Numbers to and from Test Stand are always a double type. The next line converts it to an integer.
    To put a LabWindows value to TestStand, use TS_PropertyPutValNumber.
    To pass values from a sequence call step to a called sequence, create variables in the Parameters t
    ab on your main sequence. Create same variables on the Parameters tab of the called sequence. In main, specify module to be called in calling step. There is a paramters section on the Edit Sequence Call dialog box which appears. Check the Use Prototype of the Selected Sequence box. You can then list all the parameter variables in the parameters section.
    Hope this is what you want.
    - tbob
    Inventor of the WORM Global

  • Passing Arguments in a Multiple JFrame project

    I am trying to pass Arguments from MainApp.java to SubApp.java.
    Is there someone that have an example or fix the sample program included?
    tks a lot
    sage49
    I based my program on the following 2 programs that I got from this forum!!
    The following is the MainApp.java
    import javax.swing.*;
    import java.awt.event.*;
    class MainApp extends JFrame {
        MainApp() {
            super( "Main Application" );
            JButton button = new JButton( "Show Sub Application" );
            button.addActionListener( new ActionListener() {
                public void actionPerformed( ActionEvent e ) {
    //  need to pass a string to SubApp in the following line
                    JFrame app = new SubApp();
                    dispose(); 
            getContentPane().add( button );
            setDefaultCloseOperation( DISPOSE_ON_CLOSE );
            pack();
            show();
        public static void main( String[] args ) {
            MainApp app = new MainApp();
    }The following is the SubApp.java
    import javax.swing.*;
    import java.awt.event.*;
    class SubApp extends JFrame {
    // need to accept a String as Arguments
        SubApp() {
            super( "Another Application" );
            JButton button = new JButton( "Show Main Application" );
            button.addActionListener( new ActionListener() {
                public void actionPerformed( ActionEvent e ) {
                    JFrame app = new MainApp();
                    dispose();
            getContentPane().add( button );
            setDefaultCloseOperation( DISPOSE_ON_CLOSE );
            pack();
            show();
        public static void main( String[] args ) {
            SubApp app = new SubApp();
    }

    Hi,
    I have done what you suggested, Now I get an error on the subApp on the main.
    see What I tried in the code.
    MainApp.java
    import javax.swing.*;
    import java.awt.event.*;
    class MainApp extends JFrame {
        MainApp() {
            super( "Main Application" );
            final String a ="this is the string";
            JButton button = new JButton( "Show Sub Application" );
            button.addActionListener( new ActionListener() {
                public void actionPerformed( ActionEvent e ) {
                    JFrame app = new SubApp(a);
                    dispose(); 
            getContentPane().add( button );
            setDefaultCloseOperation( DISPOSE_ON_CLOSE );
            pack();
            show();
        public static void main( String[] args ) {
            MainApp app = new MainApp();
    }The SubApp.java
    import javax.swing.*;
    import java.awt.event.*;
    class SubApp extends JFrame {
            private String mystring;
            SubApp(String mystring) {   
            super( "Another Application" );
            this.mystring = mystring;
            JButton button = new JButton( "Show Main Application" );
            button.addActionListener( new ActionListener() {
                public void actionPerformed( ActionEvent e ) {
                    JFrame app = new MainApp();
                    dispose(); 
            getContentPane().add( button );
            setDefaultCloseOperation( DISPOSE_ON_CLOSE );
            pack();
            show();
        public static void main( String[] args ) {
           // tried    =    SubApp app = new SubApp(mystring);
           // tried    =    SubApp app = new SubApp(a);
           // tried    =    SubApp app = new SubApp(String a);  
           // tried    =    SubApp app = new SubApp(String);                 
            SubApp app = new SubApp();                // this is the line I get the error
    }I get the following error:
    Cannot find Symbol
    symbol  : constructor SubApp()
    location: class SubApp
            SubApp app = new SubApp();Tks a lot
    sage49

  • Creating pocess intance of a different process and passing arguments

    Creating Process instance of a different process:
    I have two different process: Main_Flow (id: MainFlow) and Second_Flow (id: SecondFlow). In the first process I am reading a csv file. Each line of the file has four columns. After reading each line I have to initiate Second_Flow and pass the read data from the file. (Pls find the code below for the whole process):
         fileReader = FileReader(arg1 : fullFileName);//filename is of file type and have file name and path
         Java.Io.BufferedReader reader = BufferedReader(arg1 : fileReader);
         String str;
         int countLines = 0;
         while ((str = reader.readLine()) != null)
              strColumn = str.split(delim : ",");
                   int ColumnCnt = 0;
                   while (ColumnCnt < 4)
                        //defining variables
                        String appNo;
                        String custNo;
                        String loanAmm;
                        String loanDate;
                        //logMessage("Value at Column: " + ColumnCnt + " is " + strColumn[ColumnCnt]);
                        if (ColumnCnt == 0)
                             arrLoanData["appNo"] = strColumn[ColumnCnt];
                        else if (ColumnCnt == 1)
                             arrLoanData["custNo"] = strColumn[ColumnCnt];
                        else if (ColumnCnt == 2)
                             arrLoanData["loanAmm"] = strColumn[ColumnCnt];
                        else if (ColumnCnt == 3)
                             arrLoanData["loanDate"] = strColumn[ColumnCnt];
                        arrLoanData["descriptionArg"] = "AutoInstance: " + formatTime('now', timeStyle : Time.SHORT);
                        arrLoanData["genByArg"] = "Automatic";
                        ProcessInstance.create(processId : "/SecondFlow", arguments : arrLoanData, argumentsSetName : "BeginIn");
                        ColumnCnt = ColumnCnt + 1;
              countLines = countLines + 1;     
    (“The code is in Java and not in PBL”)
    I have to pass appNo, custNo, loanAmm and loanDate as the arguments. The Argument will be of Any[String] type. The argument set name of Second_Flow is “BeginIn”. But I am not getting anything in Second_Flow.
    What can I do in the argument mapping of begin of Second_Flow to get the passed argument (array)?

    the argument 'arguments' for the method ProcessInstance.create receives a map of the arguments that the 'argumentSetName' argument set will receive.
    so for example if your second flow has 2 arguments, String name, Decimal value and String[] content your method invocation would be:
    ProcessInstance.create(processId : "/SecondFlow", arguments : {"name": strNameFromCsv, "value": valueFromCsv, "content": ["a","b","c","d"]}, argumentsSetName : "BeginIn");

  • How to pass argument in main function ?

    How to pass arguments in main function of one class from another class ?
    I don't want to pass argument from command prompt.
    I want to try something like this -
    class Test{
    public static void main(String args[]){
    for(int i=0;i<args.length;i++)
         System.out.println(args);
    class Fun{
    public static void main(String args[]){
         Test t=new Test("Hello","good bye");
    when i run Fun class it gives error.
    Suggest me how can i do that.

    In Fun class main method does not take arguments that is fine. In Test class instead of main method you can have constructor to take input parameters as suggested by BalusC
    However, if you want to make your existing code work, you can call (though not appropriate) main() method of Test class from main() method of Fun class (As main() method is static object is not required to invoke this):
    Test.main(new String[]{"Hello","good bye"});Here is your code:
    class Test{
    public static void main(String args[]){
    for(int i=0;i<args.length;i++)
    System.out.println(args);
    public class Fun{
    public static void main(String args[]){
    //Test t=new Test("Hello","good bye");
    Test.main(new String[]{"Hello","good bye"});
    } Thanks,
    Mrityunjoy                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Passing arguments to a custom component in the constructor

    I would like to know if it is possible to pass arguments to a
    custom component in the constructor when I'm instantiating it
    within Actionscript. I've not seen anyone do this, so at the moment
    I have a couple of public properties defined on the custom
    component and then do the following:
    var myComponent:TestComponent = new TestComponent();
    myComponent.propertyOne = true;
    myComponent.propertyTwo = 12;
    etc.
    Whereas I'd like to do something like:
    var myComponent:TestComponent = new TestComponent( true, 12
    Any ideas if this is possible?

    Another approach as opposed to creating init function is to link symbol with autogenerated class (just assign it a class but do not create *.as file for it) and use it just as graphical view with no functionality (well only MovieClip's functionality).
    ViewClip.as
    public class ViewClip extends MovieClip {
        public var view:MovieClip;
        public function ViewClip(){
            this.view = instantiateView();
            this.addChild(view);
        protected function instantiateView():MovieClip {
            return new MovieClip();
    Circle.as
    public class Circle extends ViewClip {
        public function Circle(scaleX:Number, scaleY:Number) {
            super();
        override protected function instantiateView():MovieClip {
            return new ClassView();

  • Pass arguments to JSF tag attributes like id oder value

    Hi!
    I started with JSF some weeks ago and have some questions that i could not find in FAQ or tutorials.
    My page structure uses some <jsp:includes>. Each included page uses JSF.
    The structure is (example - users):
    Users.jsp
    |
    |(incl)
    |
    Mainpage.jsp (=Framework)
    |
    |(incl)
    |
    Browser.jsp (=Table)
    In "Users" all specific data is set. In "Browser" there is a <h:form> tag and a <h:dataTable> tag.
    The result should be a simple table with users inside.
    So I want to pass arguments to those sub-pages.
    1) -> form-ids as parameter:
    <h:form id="#{sessionScope.formName}">
    ... does not work, because ids have to start with a character or "_".
    formName is set as followed:
    session.setAttribute("formName", "form_users");
    2) ->beans as parameter:
    <h:dataTable id="browser_table_#{sessionScope.id}" styleClass="browser_table"
    var="user" value="#{sessionScope.user_list}">
    ... does not work. "id" is requested to be a static value and "value" can't find the bean by this string.
    user_list is set as followed:
    session.setAttribute("user_list", "UserListBean.users");
    (UserListBean.users is an ArrayList)
    Is there an error in my thinking? Or is there a way to pass arguments as i want?
    Thanks!

    sorry ... mistake in topic: "oder" = "or" of course :)

  • RMI Codebase Passing Arguments

    I'm new to RMI and Java.How do you pass arguments using serialization in RMI? I'll be passing the arguments from a servlet. for example if i want to pass a string object from a servlet to the calling client service. Thanks

    Can you please provide me with a better direction in terms of developments (i.e examples)? thank you

Maybe you are looking for

  • HT5114 How do you change the Apple ID that is already hooked up to the iCloud?

    My family got all new iPhones for Christmas and I got one last year so I am keeping mine. We have a plan for iCloud that we all share the same data. But we found out that if you have multiple Apple ID's then everyone will have their own iCloud. But t

  • SEARCH HELP for a screen designed in HTML

    Hello All, i have designed a screen with input fields in html and i have called the screen in abap report...everything works fine but now i need to assign search help to the fields...... can anyone help me in this....thanks in advance points will be

  • Pre-Order Bonus - Same Title on Different Platform

    If a qualifying title is preordered on two separate consoles, does the pre-order bonus apply to both since they are differnt skus or just once? For example, if I preorder Wolfenstein on PS4 and Xbox One, will I receive $20 in bonus points or $40?  Th

  • Rtf:Sum null

    Hi, I want my pdf report to look like Type                        --Best-Qual---Mid-Qual---Non-Qual M                                     20.69%-----79.31%----0.00% V                                     100.00%----0.00%-----0.00% Total               

  • Skype crashes on hungarian android when contacting...

    skype crashes when im trying to contact my daughter, who i talk with the most frequently from my contacts. I can message and call everybody from my contact list, except for her. when tapping her name, skype closes and the option to send a crash repor