Calling inputs to myProgram from different directories











up vote
0
down vote

favorite












myProgram takes three files as inputs, like so:



$ myProgram inputA inputB inputC


And say these inputs themselves reside in their own respective directories w/ some additional files:



directoryA
inputA
inputA_helperfile1
inputA_helperfile2
directoryB
inputB
inputB_helperfile1
inputB_helperfile2
directoryC
inputC
inputC_helperfile1
inputC_helperfile2


myProgram will not run properly unless all three inputs as well as these additional files (dependencies? Is that the right term?) are in the same directory. But I do not want to put all these files into the same directory in order to execute myProgram. Is there a workaround for this scenario?



I am very new to bash (and programming/scripting in general), so please forgive me if this is a trivial question! (It is non-trivial to me, and I was unable to find an adequate answer by Googling for it.)










share|improve this question






















  • Sounds like you either want to a) take the directory as the argument, or b) pass the full path. What do you currently do if the files foo/inputA and bar/inputA exist? Do you want to locate each and process both? If so, require the caller to pass them both.
    – William Pursell
    Dec 3 at 12:11










  • @WilliamPursell it was actually more of a pass the full path issue (which did work out in the end). Thanks for your inputs!
    – Dunois
    1 hour ago















up vote
0
down vote

favorite












myProgram takes three files as inputs, like so:



$ myProgram inputA inputB inputC


And say these inputs themselves reside in their own respective directories w/ some additional files:



directoryA
inputA
inputA_helperfile1
inputA_helperfile2
directoryB
inputB
inputB_helperfile1
inputB_helperfile2
directoryC
inputC
inputC_helperfile1
inputC_helperfile2


myProgram will not run properly unless all three inputs as well as these additional files (dependencies? Is that the right term?) are in the same directory. But I do not want to put all these files into the same directory in order to execute myProgram. Is there a workaround for this scenario?



I am very new to bash (and programming/scripting in general), so please forgive me if this is a trivial question! (It is non-trivial to me, and I was unable to find an adequate answer by Googling for it.)










share|improve this question






















  • Sounds like you either want to a) take the directory as the argument, or b) pass the full path. What do you currently do if the files foo/inputA and bar/inputA exist? Do you want to locate each and process both? If so, require the caller to pass them both.
    – William Pursell
    Dec 3 at 12:11










  • @WilliamPursell it was actually more of a pass the full path issue (which did work out in the end). Thanks for your inputs!
    – Dunois
    1 hour ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











myProgram takes three files as inputs, like so:



$ myProgram inputA inputB inputC


And say these inputs themselves reside in their own respective directories w/ some additional files:



directoryA
inputA
inputA_helperfile1
inputA_helperfile2
directoryB
inputB
inputB_helperfile1
inputB_helperfile2
directoryC
inputC
inputC_helperfile1
inputC_helperfile2


myProgram will not run properly unless all three inputs as well as these additional files (dependencies? Is that the right term?) are in the same directory. But I do not want to put all these files into the same directory in order to execute myProgram. Is there a workaround for this scenario?



I am very new to bash (and programming/scripting in general), so please forgive me if this is a trivial question! (It is non-trivial to me, and I was unable to find an adequate answer by Googling for it.)










share|improve this question













myProgram takes three files as inputs, like so:



$ myProgram inputA inputB inputC


And say these inputs themselves reside in their own respective directories w/ some additional files:



directoryA
inputA
inputA_helperfile1
inputA_helperfile2
directoryB
inputB
inputB_helperfile1
inputB_helperfile2
directoryC
inputC
inputC_helperfile1
inputC_helperfile2


myProgram will not run properly unless all three inputs as well as these additional files (dependencies? Is that the right term?) are in the same directory. But I do not want to put all these files into the same directory in order to execute myProgram. Is there a workaround for this scenario?



I am very new to bash (and programming/scripting in general), so please forgive me if this is a trivial question! (It is non-trivial to me, and I was unable to find an adequate answer by Googling for it.)







bash shell scripting






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 15:20









Dunois

103




103












  • Sounds like you either want to a) take the directory as the argument, or b) pass the full path. What do you currently do if the files foo/inputA and bar/inputA exist? Do you want to locate each and process both? If so, require the caller to pass them both.
    – William Pursell
    Dec 3 at 12:11










  • @WilliamPursell it was actually more of a pass the full path issue (which did work out in the end). Thanks for your inputs!
    – Dunois
    1 hour ago


















  • Sounds like you either want to a) take the directory as the argument, or b) pass the full path. What do you currently do if the files foo/inputA and bar/inputA exist? Do you want to locate each and process both? If so, require the caller to pass them both.
    – William Pursell
    Dec 3 at 12:11










  • @WilliamPursell it was actually more of a pass the full path issue (which did work out in the end). Thanks for your inputs!
    – Dunois
    1 hour ago
















Sounds like you either want to a) take the directory as the argument, or b) pass the full path. What do you currently do if the files foo/inputA and bar/inputA exist? Do you want to locate each and process both? If so, require the caller to pass them both.
– William Pursell
Dec 3 at 12:11




Sounds like you either want to a) take the directory as the argument, or b) pass the full path. What do you currently do if the files foo/inputA and bar/inputA exist? Do you want to locate each and process both? If so, require the caller to pass them both.
– William Pursell
Dec 3 at 12:11












@WilliamPursell it was actually more of a pass the full path issue (which did work out in the end). Thanks for your inputs!
– Dunois
1 hour ago




@WilliamPursell it was actually more of a pass the full path issue (which did work out in the end). Thanks for your inputs!
– Dunois
1 hour ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













It might be easier to propose a good solution if you would explain what exactly myProgram is. Did you implement it?
Is it documented that it requires all files to be in one directory?
What happens if you call your program like this?



myProgram directoryA/inputA directoryB/inputB directoryC/inputC


If myProgram requires that all files are in the same directory, you could write a script that creates a temporary directory, changes the working directory into this temporary directory, copies all files there, executes myProgram inputA inputB inputC, leaves the temporary directory and removes it including all contents.



Instead of copying the files you can also create symbolic links in the temporary directory if your file system allows this.



You probably would implement your script to be called like this



myScript directoryA/inputA directoryB/inputB directoryC/inputC


You could use dirname and find to list all files from directory[ABC] if your program needs all files that reside in these directories. Otherwise you have to specify how to find out which of all the files are inputA_helperfile1 etc.



You may have to handle duplicate file names. If e.g. inputA_helperfile1 and inputB_helperfile1 would actually be the same file names with different content you cannot copy both files into the same directory.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434010%2fcalling-inputs-to-myprogram-from-different-directories%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    It might be easier to propose a good solution if you would explain what exactly myProgram is. Did you implement it?
    Is it documented that it requires all files to be in one directory?
    What happens if you call your program like this?



    myProgram directoryA/inputA directoryB/inputB directoryC/inputC


    If myProgram requires that all files are in the same directory, you could write a script that creates a temporary directory, changes the working directory into this temporary directory, copies all files there, executes myProgram inputA inputB inputC, leaves the temporary directory and removes it including all contents.



    Instead of copying the files you can also create symbolic links in the temporary directory if your file system allows this.



    You probably would implement your script to be called like this



    myScript directoryA/inputA directoryB/inputB directoryC/inputC


    You could use dirname and find to list all files from directory[ABC] if your program needs all files that reside in these directories. Otherwise you have to specify how to find out which of all the files are inputA_helperfile1 etc.



    You may have to handle duplicate file names. If e.g. inputA_helperfile1 and inputB_helperfile1 would actually be the same file names with different content you cannot copy both files into the same directory.






    share|improve this answer



























      up vote
      0
      down vote













      It might be easier to propose a good solution if you would explain what exactly myProgram is. Did you implement it?
      Is it documented that it requires all files to be in one directory?
      What happens if you call your program like this?



      myProgram directoryA/inputA directoryB/inputB directoryC/inputC


      If myProgram requires that all files are in the same directory, you could write a script that creates a temporary directory, changes the working directory into this temporary directory, copies all files there, executes myProgram inputA inputB inputC, leaves the temporary directory and removes it including all contents.



      Instead of copying the files you can also create symbolic links in the temporary directory if your file system allows this.



      You probably would implement your script to be called like this



      myScript directoryA/inputA directoryB/inputB directoryC/inputC


      You could use dirname and find to list all files from directory[ABC] if your program needs all files that reside in these directories. Otherwise you have to specify how to find out which of all the files are inputA_helperfile1 etc.



      You may have to handle duplicate file names. If e.g. inputA_helperfile1 and inputB_helperfile1 would actually be the same file names with different content you cannot copy both files into the same directory.






      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        It might be easier to propose a good solution if you would explain what exactly myProgram is. Did you implement it?
        Is it documented that it requires all files to be in one directory?
        What happens if you call your program like this?



        myProgram directoryA/inputA directoryB/inputB directoryC/inputC


        If myProgram requires that all files are in the same directory, you could write a script that creates a temporary directory, changes the working directory into this temporary directory, copies all files there, executes myProgram inputA inputB inputC, leaves the temporary directory and removes it including all contents.



        Instead of copying the files you can also create symbolic links in the temporary directory if your file system allows this.



        You probably would implement your script to be called like this



        myScript directoryA/inputA directoryB/inputB directoryC/inputC


        You could use dirname and find to list all files from directory[ABC] if your program needs all files that reside in these directories. Otherwise you have to specify how to find out which of all the files are inputA_helperfile1 etc.



        You may have to handle duplicate file names. If e.g. inputA_helperfile1 and inputB_helperfile1 would actually be the same file names with different content you cannot copy both files into the same directory.






        share|improve this answer














        It might be easier to propose a good solution if you would explain what exactly myProgram is. Did you implement it?
        Is it documented that it requires all files to be in one directory?
        What happens if you call your program like this?



        myProgram directoryA/inputA directoryB/inputB directoryC/inputC


        If myProgram requires that all files are in the same directory, you could write a script that creates a temporary directory, changes the working directory into this temporary directory, copies all files there, executes myProgram inputA inputB inputC, leaves the temporary directory and removes it including all contents.



        Instead of copying the files you can also create symbolic links in the temporary directory if your file system allows this.



        You probably would implement your script to be called like this



        myScript directoryA/inputA directoryB/inputB directoryC/inputC


        You could use dirname and find to list all files from directory[ABC] if your program needs all files that reside in these directories. Otherwise you have to specify how to find out which of all the files are inputA_helperfile1 etc.



        You may have to handle duplicate file names. If e.g. inputA_helperfile1 and inputB_helperfile1 would actually be the same file names with different content you cannot copy both files into the same directory.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 3 at 11:59

























        answered Nov 22 at 16:52









        Bodo

        25117




        25117






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434010%2fcalling-inputs-to-myprogram-from-different-directories%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            How to ignore python UserWarning in pytest?

            Alexandru Averescu