echo names and values of all env variables that start with “nlu_setting”

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





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
-1
down vote

favorite












I am looking for a way to echo names and values of all env variables that start with nlu_setting, so the output might look like:



nlu_setting_json=true
nlu_setting_global=0
nlu_setting_bar=foo


does anyone know how to do this?







share|improve this question



















  • Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
    – JdeBP
    2 days ago
















up vote
-1
down vote

favorite












I am looking for a way to echo names and values of all env variables that start with nlu_setting, so the output might look like:



nlu_setting_json=true
nlu_setting_global=0
nlu_setting_bar=foo


does anyone know how to do this?







share|improve this question



















  • Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
    – JdeBP
    2 days ago












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am looking for a way to echo names and values of all env variables that start with nlu_setting, so the output might look like:



nlu_setting_json=true
nlu_setting_global=0
nlu_setting_bar=foo


does anyone know how to do this?







share|improve this question











I am looking for a way to echo names and values of all env variables that start with nlu_setting, so the output might look like:



nlu_setting_json=true
nlu_setting_global=0
nlu_setting_bar=foo


does anyone know how to do this?









share|improve this question










share|improve this question




share|improve this question









asked 2 days ago









Alexander Mills

1,834929




1,834929











  • Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
    – JdeBP
    2 days ago
















  • Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
    – JdeBP
    2 days ago















Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
– JdeBP
2 days ago




Environment variables? Or shell variables? The difference is important, as it rules in/out several answers.
– JdeBP
2 days ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










for var in "$!nlu_setting_@"; do
printf '%s=%sn' "$var" "$!var"
done


The expansion $!nlu_setting@ is a bash-specific expansion that returns a list of variable names matching a particular prefix. Here we use it to as for all names that start with the string nlu_setting_. We loop over these names and output the name along with the value of that variable.



We get the value of the variable using variable indirection ($!var).






share|improve this answer























  • do you think this is better than the compgen solution?
    – Alexander Mills
    2 days ago










  • @AlexanderMills I would say that it will be more efficient as it's not calling grep. Your solution would also pick up variable names that contain nlu_setting_ anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
    – Kusalananda
    2 days ago











  • ah yes good point
    – Alexander Mills
    2 days ago

















up vote
0
down vote













After looking at the answers to this question, I came up with this:



 compgen -A variable | grep "nlu_setting_" | while read v; do
echo "$v = $!v";
done


it seems to work. Never heard of the compgen command, but if it's universal bash built-in, it should be all good..






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%2f460462%2fecho-names-and-values-of-all-env-variables-that-start-with-nlu-setting%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    for var in "$!nlu_setting_@"; do
    printf '%s=%sn' "$var" "$!var"
    done


    The expansion $!nlu_setting@ is a bash-specific expansion that returns a list of variable names matching a particular prefix. Here we use it to as for all names that start with the string nlu_setting_. We loop over these names and output the name along with the value of that variable.



    We get the value of the variable using variable indirection ($!var).






    share|improve this answer























    • do you think this is better than the compgen solution?
      – Alexander Mills
      2 days ago










    • @AlexanderMills I would say that it will be more efficient as it's not calling grep. Your solution would also pick up variable names that contain nlu_setting_ anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
      – Kusalananda
      2 days ago











    • ah yes good point
      – Alexander Mills
      2 days ago














    up vote
    2
    down vote



    accepted










    for var in "$!nlu_setting_@"; do
    printf '%s=%sn' "$var" "$!var"
    done


    The expansion $!nlu_setting@ is a bash-specific expansion that returns a list of variable names matching a particular prefix. Here we use it to as for all names that start with the string nlu_setting_. We loop over these names and output the name along with the value of that variable.



    We get the value of the variable using variable indirection ($!var).






    share|improve this answer























    • do you think this is better than the compgen solution?
      – Alexander Mills
      2 days ago










    • @AlexanderMills I would say that it will be more efficient as it's not calling grep. Your solution would also pick up variable names that contain nlu_setting_ anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
      – Kusalananda
      2 days ago











    • ah yes good point
      – Alexander Mills
      2 days ago












    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    for var in "$!nlu_setting_@"; do
    printf '%s=%sn' "$var" "$!var"
    done


    The expansion $!nlu_setting@ is a bash-specific expansion that returns a list of variable names matching a particular prefix. Here we use it to as for all names that start with the string nlu_setting_. We loop over these names and output the name along with the value of that variable.



    We get the value of the variable using variable indirection ($!var).






    share|improve this answer















    for var in "$!nlu_setting_@"; do
    printf '%s=%sn' "$var" "$!var"
    done


    The expansion $!nlu_setting@ is a bash-specific expansion that returns a list of variable names matching a particular prefix. Here we use it to as for all names that start with the string nlu_setting_. We loop over these names and output the name along with the value of that variable.



    We get the value of the variable using variable indirection ($!var).







    share|improve this answer















    share|improve this answer



    share|improve this answer








    edited 2 days ago


























    answered 2 days ago









    Kusalananda

    100k13199311




    100k13199311











    • do you think this is better than the compgen solution?
      – Alexander Mills
      2 days ago










    • @AlexanderMills I would say that it will be more efficient as it's not calling grep. Your solution would also pick up variable names that contain nlu_setting_ anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
      – Kusalananda
      2 days ago











    • ah yes good point
      – Alexander Mills
      2 days ago
















    • do you think this is better than the compgen solution?
      – Alexander Mills
      2 days ago










    • @AlexanderMills I would say that it will be more efficient as it's not calling grep. Your solution would also pick up variable names that contain nlu_setting_ anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
      – Kusalananda
      2 days ago











    • ah yes good point
      – Alexander Mills
      2 days ago















    do you think this is better than the compgen solution?
    – Alexander Mills
    2 days ago




    do you think this is better than the compgen solution?
    – Alexander Mills
    2 days ago












    @AlexanderMills I would say that it will be more efficient as it's not calling grep. Your solution would also pick up variable names that contain nlu_setting_ anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
    – Kusalananda
    2 days ago





    @AlexanderMills I would say that it will be more efficient as it's not calling grep. Your solution would also pick up variable names that contain nlu_setting_ anywhere, not just at the start of the variable name (due to the non-anchored regular expression that you are using).
    – Kusalananda
    2 days ago













    ah yes good point
    – Alexander Mills
    2 days ago




    ah yes good point
    – Alexander Mills
    2 days ago












    up vote
    0
    down vote













    After looking at the answers to this question, I came up with this:



     compgen -A variable | grep "nlu_setting_" | while read v; do
    echo "$v = $!v";
    done


    it seems to work. Never heard of the compgen command, but if it's universal bash built-in, it should be all good..






    share|improve this answer

























      up vote
      0
      down vote













      After looking at the answers to this question, I came up with this:



       compgen -A variable | grep "nlu_setting_" | while read v; do
      echo "$v = $!v";
      done


      it seems to work. Never heard of the compgen command, but if it's universal bash built-in, it should be all good..






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        After looking at the answers to this question, I came up with this:



         compgen -A variable | grep "nlu_setting_" | while read v; do
        echo "$v = $!v";
        done


        it seems to work. Never heard of the compgen command, but if it's universal bash built-in, it should be all good..






        share|improve this answer













        After looking at the answers to this question, I came up with this:



         compgen -A variable | grep "nlu_setting_" | while read v; do
        echo "$v = $!v";
        done


        it seems to work. Never heard of the compgen command, but if it's universal bash built-in, it should be all good..







        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered 2 days ago









        Alexander Mills

        1,834929




        1,834929






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460462%2fecho-names-and-values-of-all-env-variables-that-start-with-nlu-setting%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?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay