in bash language, how can i define a list of paths of files?

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











up vote
-2
down vote

favorite












In bash language, how can I define a list of paths?



I need something like below:



list_of_paths = ["$Home/MyDir/test.c", "$Home/YourDir/file.c"]







share|improve this question

























    up vote
    -2
    down vote

    favorite












    In bash language, how can I define a list of paths?



    I need something like below:



    list_of_paths = ["$Home/MyDir/test.c", "$Home/YourDir/file.c"]







    share|improve this question























      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite











      In bash language, how can I define a list of paths?



      I need something like below:



      list_of_paths = ["$Home/MyDir/test.c", "$Home/YourDir/file.c"]







      share|improve this question













      In bash language, how can I define a list of paths?



      I need something like below:



      list_of_paths = ["$Home/MyDir/test.c", "$Home/YourDir/file.c"]









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 28 at 10:23









      SivaPrasath

      3,88611737




      3,88611737









      asked Jun 28 at 8:50









      user297439

      1




      1




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          An array my be created in bash using



          mypaths=( "/my/first/path" "/my/second/path" )


          Elements of the array may also be assigned individually:



          mypaths[0]="/my/first/path"
          mypaths[1]="/my/second/path"


          Note that there should be no spaces around the =.



          This is described in the section called "Arrays" in the bash manual.



          Using the array:



          printf 'The 1st path is %sn' "$mypaths[0]"
          printf 'The 2nd path is %sn' "$mypaths[1]"

          for thepath in "$mypaths[@]"; do
          # use "$thepath" here
          done



          Alternative for /bin/sh (will also work in bash and in a number of other sh-like shells):



          set -- "/my/first/path" "/my/second/path"

          printf 'The 1st path is %sn' "$1"
          printf 'The 2nd path is %sn' "$2"

          for thepath do
          # use "$thepath" here
          done


          This uses the only array there is in a /bin/sh shell, which is the list of positional parameters ($1, $2, $3, etc., or collectively $@). This list usually contains the command line arguments for the script or shell function, but can be set explicitly in a script with set.



          The loop at the end may also be written



          for thepath in "$@"; do
          # use "$thepath" here
          done


          Note that the quoting of every single variable expansion is significant.






          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%2f452381%2fin-bash-language-how-can-i-define-a-list-of-paths-of-files%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













            An array my be created in bash using



            mypaths=( "/my/first/path" "/my/second/path" )


            Elements of the array may also be assigned individually:



            mypaths[0]="/my/first/path"
            mypaths[1]="/my/second/path"


            Note that there should be no spaces around the =.



            This is described in the section called "Arrays" in the bash manual.



            Using the array:



            printf 'The 1st path is %sn' "$mypaths[0]"
            printf 'The 2nd path is %sn' "$mypaths[1]"

            for thepath in "$mypaths[@]"; do
            # use "$thepath" here
            done



            Alternative for /bin/sh (will also work in bash and in a number of other sh-like shells):



            set -- "/my/first/path" "/my/second/path"

            printf 'The 1st path is %sn' "$1"
            printf 'The 2nd path is %sn' "$2"

            for thepath do
            # use "$thepath" here
            done


            This uses the only array there is in a /bin/sh shell, which is the list of positional parameters ($1, $2, $3, etc., or collectively $@). This list usually contains the command line arguments for the script or shell function, but can be set explicitly in a script with set.



            The loop at the end may also be written



            for thepath in "$@"; do
            # use "$thepath" here
            done


            Note that the quoting of every single variable expansion is significant.






            share|improve this answer



























              up vote
              2
              down vote













              An array my be created in bash using



              mypaths=( "/my/first/path" "/my/second/path" )


              Elements of the array may also be assigned individually:



              mypaths[0]="/my/first/path"
              mypaths[1]="/my/second/path"


              Note that there should be no spaces around the =.



              This is described in the section called "Arrays" in the bash manual.



              Using the array:



              printf 'The 1st path is %sn' "$mypaths[0]"
              printf 'The 2nd path is %sn' "$mypaths[1]"

              for thepath in "$mypaths[@]"; do
              # use "$thepath" here
              done



              Alternative for /bin/sh (will also work in bash and in a number of other sh-like shells):



              set -- "/my/first/path" "/my/second/path"

              printf 'The 1st path is %sn' "$1"
              printf 'The 2nd path is %sn' "$2"

              for thepath do
              # use "$thepath" here
              done


              This uses the only array there is in a /bin/sh shell, which is the list of positional parameters ($1, $2, $3, etc., or collectively $@). This list usually contains the command line arguments for the script or shell function, but can be set explicitly in a script with set.



              The loop at the end may also be written



              for thepath in "$@"; do
              # use "$thepath" here
              done


              Note that the quoting of every single variable expansion is significant.






              share|improve this answer

























                up vote
                2
                down vote










                up vote
                2
                down vote









                An array my be created in bash using



                mypaths=( "/my/first/path" "/my/second/path" )


                Elements of the array may also be assigned individually:



                mypaths[0]="/my/first/path"
                mypaths[1]="/my/second/path"


                Note that there should be no spaces around the =.



                This is described in the section called "Arrays" in the bash manual.



                Using the array:



                printf 'The 1st path is %sn' "$mypaths[0]"
                printf 'The 2nd path is %sn' "$mypaths[1]"

                for thepath in "$mypaths[@]"; do
                # use "$thepath" here
                done



                Alternative for /bin/sh (will also work in bash and in a number of other sh-like shells):



                set -- "/my/first/path" "/my/second/path"

                printf 'The 1st path is %sn' "$1"
                printf 'The 2nd path is %sn' "$2"

                for thepath do
                # use "$thepath" here
                done


                This uses the only array there is in a /bin/sh shell, which is the list of positional parameters ($1, $2, $3, etc., or collectively $@). This list usually contains the command line arguments for the script or shell function, but can be set explicitly in a script with set.



                The loop at the end may also be written



                for thepath in "$@"; do
                # use "$thepath" here
                done


                Note that the quoting of every single variable expansion is significant.






                share|improve this answer















                An array my be created in bash using



                mypaths=( "/my/first/path" "/my/second/path" )


                Elements of the array may also be assigned individually:



                mypaths[0]="/my/first/path"
                mypaths[1]="/my/second/path"


                Note that there should be no spaces around the =.



                This is described in the section called "Arrays" in the bash manual.



                Using the array:



                printf 'The 1st path is %sn' "$mypaths[0]"
                printf 'The 2nd path is %sn' "$mypaths[1]"

                for thepath in "$mypaths[@]"; do
                # use "$thepath" here
                done



                Alternative for /bin/sh (will also work in bash and in a number of other sh-like shells):



                set -- "/my/first/path" "/my/second/path"

                printf 'The 1st path is %sn' "$1"
                printf 'The 2nd path is %sn' "$2"

                for thepath do
                # use "$thepath" here
                done


                This uses the only array there is in a /bin/sh shell, which is the list of positional parameters ($1, $2, $3, etc., or collectively $@). This list usually contains the command line arguments for the script or shell function, but can be set explicitly in a script with set.



                The loop at the end may also be written



                for thepath in "$@"; do
                # use "$thepath" here
                done


                Note that the quoting of every single variable expansion is significant.







                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited Jun 28 at 13:43


























                answered Jun 28 at 8:57









                Kusalananda

                101k13199312




                101k13199312






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f452381%2fin-bash-language-how-can-i-define-a-list-of-paths-of-files%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)