Create “function” to run bash?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have the following bash:



cd /aPath/
for x in y.*.gz
> do something $file.dd.mm.yyyy >> /anotherPath/aFile
> done


I would like to pass in an argument to this file which will represent the month to insert in to 'mm'. So I would like to be able to call from the command line:



myFunc 08



and it would run:



cd /aPath/
for x in y.*.gz
> do something $file.dd.08.yyyy >> /anotherPath/aFile
> done


How do I do this/can I define something in my bash_profile ?










share|improve this question

























    up vote
    1
    down vote

    favorite












    I have the following bash:



    cd /aPath/
    for x in y.*.gz
    > do something $file.dd.mm.yyyy >> /anotherPath/aFile
    > done


    I would like to pass in an argument to this file which will represent the month to insert in to 'mm'. So I would like to be able to call from the command line:



    myFunc 08



    and it would run:



    cd /aPath/
    for x in y.*.gz
    > do something $file.dd.08.yyyy >> /anotherPath/aFile
    > done


    How do I do this/can I define something in my bash_profile ?










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have the following bash:



      cd /aPath/
      for x in y.*.gz
      > do something $file.dd.mm.yyyy >> /anotherPath/aFile
      > done


      I would like to pass in an argument to this file which will represent the month to insert in to 'mm'. So I would like to be able to call from the command line:



      myFunc 08



      and it would run:



      cd /aPath/
      for x in y.*.gz
      > do something $file.dd.08.yyyy >> /anotherPath/aFile
      > done


      How do I do this/can I define something in my bash_profile ?










      share|improve this question













      I have the following bash:



      cd /aPath/
      for x in y.*.gz
      > do something $file.dd.mm.yyyy >> /anotherPath/aFile
      > done


      I would like to pass in an argument to this file which will represent the month to insert in to 'mm'. So I would like to be able to call from the command line:



      myFunc 08



      and it would run:



      cd /aPath/
      for x in y.*.gz
      > do something $file.dd.08.yyyy >> /anotherPath/aFile
      > done


      How do I do this/can I define something in my bash_profile ?







      bash






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 25 '17 at 8:04









      user997112

      2974619




      2974619




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          I would add the function into my /home/user/.bashrc



          in example



          myFunc() 
          mm=$1
          FILES=/home/user/*
          for f in $FILES; do
          if [[ $f == filename.dd.$mm.yyyy ]]; then
          ls -la $f
          fi
          done



          and remembering to reload .bashrc file with the command source ~/.bashrc, I would call the function from the shell.



          mm=$1 will get the first parameter(argument) you passed to the function by calling myFunc 08 and put it into $mm variable (which is pretty useless step, you can directly use $1 variable wherever you need into the function)






          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            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: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394265%2fcreate-function-to-run-bash%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            I would add the function into my /home/user/.bashrc



            in example



            myFunc() 
            mm=$1
            FILES=/home/user/*
            for f in $FILES; do
            if [[ $f == filename.dd.$mm.yyyy ]]; then
            ls -la $f
            fi
            done



            and remembering to reload .bashrc file with the command source ~/.bashrc, I would call the function from the shell.



            mm=$1 will get the first parameter(argument) you passed to the function by calling myFunc 08 and put it into $mm variable (which is pretty useless step, you can directly use $1 variable wherever you need into the function)






            share|improve this answer


























              up vote
              2
              down vote



              accepted










              I would add the function into my /home/user/.bashrc



              in example



              myFunc() 
              mm=$1
              FILES=/home/user/*
              for f in $FILES; do
              if [[ $f == filename.dd.$mm.yyyy ]]; then
              ls -la $f
              fi
              done



              and remembering to reload .bashrc file with the command source ~/.bashrc, I would call the function from the shell.



              mm=$1 will get the first parameter(argument) you passed to the function by calling myFunc 08 and put it into $mm variable (which is pretty useless step, you can directly use $1 variable wherever you need into the function)






              share|improve this answer
























                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                I would add the function into my /home/user/.bashrc



                in example



                myFunc() 
                mm=$1
                FILES=/home/user/*
                for f in $FILES; do
                if [[ $f == filename.dd.$mm.yyyy ]]; then
                ls -la $f
                fi
                done



                and remembering to reload .bashrc file with the command source ~/.bashrc, I would call the function from the shell.



                mm=$1 will get the first parameter(argument) you passed to the function by calling myFunc 08 and put it into $mm variable (which is pretty useless step, you can directly use $1 variable wherever you need into the function)






                share|improve this answer














                I would add the function into my /home/user/.bashrc



                in example



                myFunc() 
                mm=$1
                FILES=/home/user/*
                for f in $FILES; do
                if [[ $f == filename.dd.$mm.yyyy ]]; then
                ls -la $f
                fi
                done



                and remembering to reload .bashrc file with the command source ~/.bashrc, I would call the function from the shell.



                mm=$1 will get the first parameter(argument) you passed to the function by calling myFunc 08 and put it into $mm variable (which is pretty useless step, you can directly use $1 variable wherever you need into the function)







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Sep 25 '17 at 8:50

























                answered Sep 25 '17 at 8:22









                lese

                2,11021227




                2,11021227



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394265%2fcreate-function-to-run-bash%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?