Array inside an Array: Different syntax for Array in bash

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











up vote
0
down vote

favorite












I found the following example from here. But I can't understand how is array arr is being defined.



a='domain.de;de;https'
$ arr=($a//;/ )


What is the advantage of defining it like this?



Actually, I want to store an array inside an array of varying size like as follows:



declare -a Workspace=(
"$Folder[0]" "CFD" "General,Markdown"
"$Folder[4]" "GPU" "General,Markdown,Python,C,Java"
)


For example in above, I want to access the terms General and Markdown for CFD.










share|improve this question



















  • 1




    Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
    – Jeff Schaller
    Nov 22 at 0:44















up vote
0
down vote

favorite












I found the following example from here. But I can't understand how is array arr is being defined.



a='domain.de;de;https'
$ arr=($a//;/ )


What is the advantage of defining it like this?



Actually, I want to store an array inside an array of varying size like as follows:



declare -a Workspace=(
"$Folder[0]" "CFD" "General,Markdown"
"$Folder[4]" "GPU" "General,Markdown,Python,C,Java"
)


For example in above, I want to access the terms General and Markdown for CFD.










share|improve this question



















  • 1




    Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
    – Jeff Schaller
    Nov 22 at 0:44













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I found the following example from here. But I can't understand how is array arr is being defined.



a='domain.de;de;https'
$ arr=($a//;/ )


What is the advantage of defining it like this?



Actually, I want to store an array inside an array of varying size like as follows:



declare -a Workspace=(
"$Folder[0]" "CFD" "General,Markdown"
"$Folder[4]" "GPU" "General,Markdown,Python,C,Java"
)


For example in above, I want to access the terms General and Markdown for CFD.










share|improve this question















I found the following example from here. But I can't understand how is array arr is being defined.



a='domain.de;de;https'
$ arr=($a//;/ )


What is the advantage of defining it like this?



Actually, I want to store an array inside an array of varying size like as follows:



declare -a Workspace=(
"$Folder[0]" "CFD" "General,Markdown"
"$Folder[4]" "GPU" "General,Markdown,Python,C,Java"
)


For example in above, I want to access the terms General and Markdown for CFD.







bash shell-script array gnu bash-array






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 0:28

























asked Nov 22 at 0:19









Nikhil

20919




20919







  • 1




    Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
    – Jeff Schaller
    Nov 22 at 0:44













  • 1




    Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
    – Jeff Schaller
    Nov 22 at 0:44








1




1




Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
– Jeff Schaller
Nov 22 at 0:44





Just because you can make an array of space delimited elements in bash doesn't make it a good idea. A good fat structure is important, and if the problem is this complex, consider a more powerful and flexible language like Perl.
– Jeff Schaller
Nov 22 at 0:44











1 Answer
1






active

oldest

votes

















up vote
1
down vote













An array of arrays is a bad idea in shell (any shell). You need some other language.




how is array arr being defined.?



a='domain.de;de;https'
arr=($a//;/ )



It works by:



  • replacing every ; by an space

  • Assuming IFS is space, tab, newline (the default)

  • splitting on space (included in IFS) the unquoted expansion of $...

  • assigning it to an array (...)

  • and naming that array arr=.


What is the advantage of defining it like this?




None, only problems:



  • If any of the elements contains an space, a tab or a newline, it will be split.

  • As globbing was not turn off, any *, ? or [ ] will be expanded to matching files.

  • If nullglob is active, any string containing *,? or [ ] will be removed.

  • if failglob is active any of the previous characters will generate an error.

In short, splitting on the shell is full of gotchas.






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: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f483331%2farray-inside-an-array-different-syntax-for-array-in-bash%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
    1
    down vote













    An array of arrays is a bad idea in shell (any shell). You need some other language.




    how is array arr being defined.?



    a='domain.de;de;https'
    arr=($a//;/ )



    It works by:



    • replacing every ; by an space

    • Assuming IFS is space, tab, newline (the default)

    • splitting on space (included in IFS) the unquoted expansion of $...

    • assigning it to an array (...)

    • and naming that array arr=.


    What is the advantage of defining it like this?




    None, only problems:



    • If any of the elements contains an space, a tab or a newline, it will be split.

    • As globbing was not turn off, any *, ? or [ ] will be expanded to matching files.

    • If nullglob is active, any string containing *,? or [ ] will be removed.

    • if failglob is active any of the previous characters will generate an error.

    In short, splitting on the shell is full of gotchas.






    share|improve this answer
























      up vote
      1
      down vote













      An array of arrays is a bad idea in shell (any shell). You need some other language.




      how is array arr being defined.?



      a='domain.de;de;https'
      arr=($a//;/ )



      It works by:



      • replacing every ; by an space

      • Assuming IFS is space, tab, newline (the default)

      • splitting on space (included in IFS) the unquoted expansion of $...

      • assigning it to an array (...)

      • and naming that array arr=.


      What is the advantage of defining it like this?




      None, only problems:



      • If any of the elements contains an space, a tab or a newline, it will be split.

      • As globbing was not turn off, any *, ? or [ ] will be expanded to matching files.

      • If nullglob is active, any string containing *,? or [ ] will be removed.

      • if failglob is active any of the previous characters will generate an error.

      In short, splitting on the shell is full of gotchas.






      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        An array of arrays is a bad idea in shell (any shell). You need some other language.




        how is array arr being defined.?



        a='domain.de;de;https'
        arr=($a//;/ )



        It works by:



        • replacing every ; by an space

        • Assuming IFS is space, tab, newline (the default)

        • splitting on space (included in IFS) the unquoted expansion of $...

        • assigning it to an array (...)

        • and naming that array arr=.


        What is the advantage of defining it like this?




        None, only problems:



        • If any of the elements contains an space, a tab or a newline, it will be split.

        • As globbing was not turn off, any *, ? or [ ] will be expanded to matching files.

        • If nullglob is active, any string containing *,? or [ ] will be removed.

        • if failglob is active any of the previous characters will generate an error.

        In short, splitting on the shell is full of gotchas.






        share|improve this answer












        An array of arrays is a bad idea in shell (any shell). You need some other language.




        how is array arr being defined.?



        a='domain.de;de;https'
        arr=($a//;/ )



        It works by:



        • replacing every ; by an space

        • Assuming IFS is space, tab, newline (the default)

        • splitting on space (included in IFS) the unquoted expansion of $...

        • assigning it to an array (...)

        • and naming that array arr=.


        What is the advantage of defining it like this?




        None, only problems:



        • If any of the elements contains an space, a tab or a newline, it will be split.

        • As globbing was not turn off, any *, ? or [ ] will be expanded to matching files.

        • If nullglob is active, any string containing *,? or [ ] will be removed.

        • if failglob is active any of the previous characters will generate an error.

        In short, splitting on the shell is full of gotchas.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 0:44









        Isaac

        9,72811445




        9,72811445



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483331%2farray-inside-an-array-different-syntax-for-array-in-bash%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

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

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay