Creating a permanent variableHow to make a permanent variableKeep global variables values piping through functionsHow do I set an environment variable for sudo in MacOS?How to print the values of variables with incremented numbers using a loop in shell script?Cron Bash Script - echo to current terminal instead of /var/spool/mail/rootConditional execution block with || and parentheses problemSeparating variable names from output strings with no whitespaceChange default login shell to /bin/bash for ALL ldap users from LDAP server - not clientVariable Crossover in multiple bash scripts?Using a variable to execute a curl commandCron shell ignores runuser command - why?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

How does Loki do this?

How easy is it to start Magic from scratch?

Why Were Madagascar and New Zealand Discovered So Late?

How did Doctor Strange see the winning outcome in Avengers: Infinity War?

Gears on left are inverse to gears on right?

Anatomically Correct Strange Women In Ponds Distributing Swords

Sequence of Tenses: Translating the subjunctive

What can we do to stop prior company from asking us questions?

How to safely derail a train during transit?

Is there a korbon needed for conversion?

Do sorcerers' Subtle Spells require a skill check to be unseen?

Proof of work - lottery approach

How does it work when somebody invests in my business?

How to write papers efficiently when English isn't my first language?

Would a high gravity rocky planet be guaranteed to have an atmosphere?

How did Arya survive the stabbing?

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

Roman Numeral Treatment of Suspensions

Type int? vs type int

Inappropriate reference requests from Journal reviewers

Class Action - which options I have?

Is a stroke of luck acceptable after a series of unfavorable events?

Is expanding the research of a group into machine learning as a PhD student risky?



Creating a permanent variable


How to make a permanent variableKeep global variables values piping through functionsHow do I set an environment variable for sudo in MacOS?How to print the values of variables with incremented numbers using a loop in shell script?Cron Bash Script - echo to current terminal instead of /var/spool/mail/rootConditional execution block with || and parentheses problemSeparating variable names from output strings with no whitespaceChange default login shell to /bin/bash for ALL ldap users from LDAP server - not clientVariable Crossover in multiple bash scripts?Using a variable to execute a curl commandCron shell ignores runuser command - why?













1















Is it possible to set "permanent variable" in shell? For example,
when I log in I want to print message "Hello user, this is your xxx log in"



The number of logins would be stored in permanent variable, and each time it would be incremented by script e.g



#!/bin/bash
echo "Hello Mr. This is your $number log in"
$number=$(($number+1))


The next log in would print the incremented variable and increment it again.



How could I set a variable like that?










share|improve this question



















  • 3





    You need to write that number into a file and read from file every time you login, in your .profile or .bashrc or equivalent.

    – MelBurslan
    Mar 3 '16 at 20:15






  • 2





    That's literally what files are for.

    – PSkocik
    Mar 3 '16 at 20:22











  • you also have to think about what you consider to be a "login". You can login at the console, or over the network (e.g. via ssh). Most terminal apps can be configured so that each tab can be treated as a login shell. So what you consider to be a login and what (various parts of) the system considers to be a login may be completely different.

    – cas
    Mar 3 '16 at 21:30
















1















Is it possible to set "permanent variable" in shell? For example,
when I log in I want to print message "Hello user, this is your xxx log in"



The number of logins would be stored in permanent variable, and each time it would be incremented by script e.g



#!/bin/bash
echo "Hello Mr. This is your $number log in"
$number=$(($number+1))


The next log in would print the incremented variable and increment it again.



How could I set a variable like that?










share|improve this question



















  • 3





    You need to write that number into a file and read from file every time you login, in your .profile or .bashrc or equivalent.

    – MelBurslan
    Mar 3 '16 at 20:15






  • 2





    That's literally what files are for.

    – PSkocik
    Mar 3 '16 at 20:22











  • you also have to think about what you consider to be a "login". You can login at the console, or over the network (e.g. via ssh). Most terminal apps can be configured so that each tab can be treated as a login shell. So what you consider to be a login and what (various parts of) the system considers to be a login may be completely different.

    – cas
    Mar 3 '16 at 21:30














1












1








1








Is it possible to set "permanent variable" in shell? For example,
when I log in I want to print message "Hello user, this is your xxx log in"



The number of logins would be stored in permanent variable, and each time it would be incremented by script e.g



#!/bin/bash
echo "Hello Mr. This is your $number log in"
$number=$(($number+1))


The next log in would print the incremented variable and increment it again.



How could I set a variable like that?










share|improve this question
















Is it possible to set "permanent variable" in shell? For example,
when I log in I want to print message "Hello user, this is your xxx log in"



The number of logins would be stored in permanent variable, and each time it would be incremented by script e.g



#!/bin/bash
echo "Hello Mr. This is your $number log in"
$number=$(($number+1))


The next log in would print the incremented variable and increment it again.



How could I set a variable like that?







bash shell shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 3 '16 at 20:36









Jeff Schaller

44k1161142




44k1161142










asked Mar 3 '16 at 20:09









J.ddJ.dd

82




82







  • 3





    You need to write that number into a file and read from file every time you login, in your .profile or .bashrc or equivalent.

    – MelBurslan
    Mar 3 '16 at 20:15






  • 2





    That's literally what files are for.

    – PSkocik
    Mar 3 '16 at 20:22











  • you also have to think about what you consider to be a "login". You can login at the console, or over the network (e.g. via ssh). Most terminal apps can be configured so that each tab can be treated as a login shell. So what you consider to be a login and what (various parts of) the system considers to be a login may be completely different.

    – cas
    Mar 3 '16 at 21:30













  • 3





    You need to write that number into a file and read from file every time you login, in your .profile or .bashrc or equivalent.

    – MelBurslan
    Mar 3 '16 at 20:15






  • 2





    That's literally what files are for.

    – PSkocik
    Mar 3 '16 at 20:22











  • you also have to think about what you consider to be a "login". You can login at the console, or over the network (e.g. via ssh). Most terminal apps can be configured so that each tab can be treated as a login shell. So what you consider to be a login and what (various parts of) the system considers to be a login may be completely different.

    – cas
    Mar 3 '16 at 21:30








3




3





You need to write that number into a file and read from file every time you login, in your .profile or .bashrc or equivalent.

– MelBurslan
Mar 3 '16 at 20:15





You need to write that number into a file and read from file every time you login, in your .profile or .bashrc or equivalent.

– MelBurslan
Mar 3 '16 at 20:15




2




2





That's literally what files are for.

– PSkocik
Mar 3 '16 at 20:22





That's literally what files are for.

– PSkocik
Mar 3 '16 at 20:22













you also have to think about what you consider to be a "login". You can login at the console, or over the network (e.g. via ssh). Most terminal apps can be configured so that each tab can be treated as a login shell. So what you consider to be a login and what (various parts of) the system considers to be a login may be completely different.

– cas
Mar 3 '16 at 21:30






you also have to think about what you consider to be a "login". You can login at the console, or over the network (e.g. via ssh). Most terminal apps can be configured so that each tab can be treated as a login shell. So what you consider to be a login and what (various parts of) the system considers to be a login may be completely different.

– cas
Mar 3 '16 at 21:30











6 Answers
6






active

oldest

votes


















1














You can't. However, you can use various hacks to do it, for example creating a file in some folder each time a user logs in, or adding a line to some file each time a user logs in. These would be easy to implement, but inefficient in long run. A much more efficient operation would be writing a number to a file, and changing it. You would, however, have to be sure that the file is structured as you want and that the number is where you expect it to be. Since these are hacks, they aren't perfect(malicious user can modify these), but could suffice for your problem.



You can count lines with wc -l






share|improve this answer
































    4














    I'd write:



    #!/bin/bash
    file=$HOME/.login_count
    number=$(<"$file")
    echo "Hello Mr. This is your $number log in"
    echo $((number+1)) > "$file"





    share|improve this answer























    • Does this properly handle malicious file contents? e.g. 7; rm -r /

      – wizzwizz4
      yesterday











    • I think it's fine: the contents of the number variable are not evaluated in the echo command (double quotes) and in arithmetic context there will be a syntax error.

      – glenn jackman
      yesterday


















    1














    Matthew Rock's answer is nice as are the other ones but like Matthew points out then the user can change these numbers. One way to circumvent that is to use PAM.



    I would put the following line in /etc/pam.d/login



    session optional pam_exec.so /usr/local/bin/someshellscript.sh


    And in /usr/local/bin/someshellscript.sh you can use variables like $PAM_USER which gives the username. Then in the shellscript you can access a file that is not writable (and perhaps not readable, depends on what you want) to the users and keep tabs on all the users and how often they have logged in, in that file. I leave the writing of that script as an exercise to the reader ;-)






    share|improve this answer






























      0














      Here's one possible hack; add the following lines to your $HOME/.bash_profile (since you tagged bash):



      NLOGINS=0
      printf "Hello Mr. This is your %d log inn" $((NLOGINS + 1))
      sed -i 's/^NLOGINS=.*/NLOGINS='$((NLOGINS + 1))'/' $HOME/.bash_profile


      Each time you log in, you'll get the printed message and then it will self-update the .bash_profile with the new NLOGINS count.






      share|improve this answer






























        0














        Look at this post https://unix.stackexchange.com/a/350163



        Permanent variables using kv-bash functions:



        1) Download kv-bash file from github:



        git clone https://github.com/damphat/kv-bash.git
        cp -ar ./kv-bash/kv-bash /usr/local
        chmod +x /usr/local/kv-bash

        # Put this line in .bash_profile (optional)
        source kv-bash


        2) Try



        #let try create/modify/delete variable
        kvset myEmail john@example.com
        kvset myCommand "Very Long Long Long String"

        #read the varible
        kvget myEmail

        #you can also use in another script with $(kvget myEmail)
        echo $(kvget myEmail)

        #delete variable
        kvdel myEmail





        share|improve this answer
































          0














          With zsh, you can use the $mapfile special associative array that gives you access to the content of a file as a variable (beware of concurrent access).



          #! /bin/zsh -
          zmodload zsh/mapfile
          echo "Hello Mr. This is your $((++mapfile[$HOME/.number]))th log in"


          fish has so-called Universal variables whose content is stored in files in your ~/.config and to which fish serializes access via some IPC mechanism.



          #! /bin/fish -
          set -U number (math 0$number+1)
          echo Hello Mr. This is your $numberth log in





          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',
            autoActivateHeartbeat: false,
            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%2f267460%2fcreating-a-permanent-variable%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            6 Answers
            6






            active

            oldest

            votes








            6 Answers
            6






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You can't. However, you can use various hacks to do it, for example creating a file in some folder each time a user logs in, or adding a line to some file each time a user logs in. These would be easy to implement, but inefficient in long run. A much more efficient operation would be writing a number to a file, and changing it. You would, however, have to be sure that the file is structured as you want and that the number is where you expect it to be. Since these are hacks, they aren't perfect(malicious user can modify these), but could suffice for your problem.



            You can count lines with wc -l






            share|improve this answer





























              1














              You can't. However, you can use various hacks to do it, for example creating a file in some folder each time a user logs in, or adding a line to some file each time a user logs in. These would be easy to implement, but inefficient in long run. A much more efficient operation would be writing a number to a file, and changing it. You would, however, have to be sure that the file is structured as you want and that the number is where you expect it to be. Since these are hacks, they aren't perfect(malicious user can modify these), but could suffice for your problem.



              You can count lines with wc -l






              share|improve this answer



























                1












                1








                1







                You can't. However, you can use various hacks to do it, for example creating a file in some folder each time a user logs in, or adding a line to some file each time a user logs in. These would be easy to implement, but inefficient in long run. A much more efficient operation would be writing a number to a file, and changing it. You would, however, have to be sure that the file is structured as you want and that the number is where you expect it to be. Since these are hacks, they aren't perfect(malicious user can modify these), but could suffice for your problem.



                You can count lines with wc -l






                share|improve this answer















                You can't. However, you can use various hacks to do it, for example creating a file in some folder each time a user logs in, or adding a line to some file each time a user logs in. These would be easy to implement, but inefficient in long run. A much more efficient operation would be writing a number to a file, and changing it. You would, however, have to be sure that the file is structured as you want and that the number is where you expect it to be. Since these are hacks, they aren't perfect(malicious user can modify these), but could suffice for your problem.



                You can count lines with wc -l







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 4 '16 at 23:24

























                answered Mar 3 '16 at 20:14









                MatthewRockMatthewRock

                4,02331848




                4,02331848























                    4














                    I'd write:



                    #!/bin/bash
                    file=$HOME/.login_count
                    number=$(<"$file")
                    echo "Hello Mr. This is your $number log in"
                    echo $((number+1)) > "$file"





                    share|improve this answer























                    • Does this properly handle malicious file contents? e.g. 7; rm -r /

                      – wizzwizz4
                      yesterday











                    • I think it's fine: the contents of the number variable are not evaluated in the echo command (double quotes) and in arithmetic context there will be a syntax error.

                      – glenn jackman
                      yesterday















                    4














                    I'd write:



                    #!/bin/bash
                    file=$HOME/.login_count
                    number=$(<"$file")
                    echo "Hello Mr. This is your $number log in"
                    echo $((number+1)) > "$file"





                    share|improve this answer























                    • Does this properly handle malicious file contents? e.g. 7; rm -r /

                      – wizzwizz4
                      yesterday











                    • I think it's fine: the contents of the number variable are not evaluated in the echo command (double quotes) and in arithmetic context there will be a syntax error.

                      – glenn jackman
                      yesterday













                    4












                    4








                    4







                    I'd write:



                    #!/bin/bash
                    file=$HOME/.login_count
                    number=$(<"$file")
                    echo "Hello Mr. This is your $number log in"
                    echo $((number+1)) > "$file"





                    share|improve this answer













                    I'd write:



                    #!/bin/bash
                    file=$HOME/.login_count
                    number=$(<"$file")
                    echo "Hello Mr. This is your $number log in"
                    echo $((number+1)) > "$file"






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 3 '16 at 20:31









                    glenn jackmanglenn jackman

                    52.7k573114




                    52.7k573114












                    • Does this properly handle malicious file contents? e.g. 7; rm -r /

                      – wizzwizz4
                      yesterday











                    • I think it's fine: the contents of the number variable are not evaluated in the echo command (double quotes) and in arithmetic context there will be a syntax error.

                      – glenn jackman
                      yesterday

















                    • Does this properly handle malicious file contents? e.g. 7; rm -r /

                      – wizzwizz4
                      yesterday











                    • I think it's fine: the contents of the number variable are not evaluated in the echo command (double quotes) and in arithmetic context there will be a syntax error.

                      – glenn jackman
                      yesterday
















                    Does this properly handle malicious file contents? e.g. 7; rm -r /

                    – wizzwizz4
                    yesterday





                    Does this properly handle malicious file contents? e.g. 7; rm -r /

                    – wizzwizz4
                    yesterday













                    I think it's fine: the contents of the number variable are not evaluated in the echo command (double quotes) and in arithmetic context there will be a syntax error.

                    – glenn jackman
                    yesterday





                    I think it's fine: the contents of the number variable are not evaluated in the echo command (double quotes) and in arithmetic context there will be a syntax error.

                    – glenn jackman
                    yesterday











                    1














                    Matthew Rock's answer is nice as are the other ones but like Matthew points out then the user can change these numbers. One way to circumvent that is to use PAM.



                    I would put the following line in /etc/pam.d/login



                    session optional pam_exec.so /usr/local/bin/someshellscript.sh


                    And in /usr/local/bin/someshellscript.sh you can use variables like $PAM_USER which gives the username. Then in the shellscript you can access a file that is not writable (and perhaps not readable, depends on what you want) to the users and keep tabs on all the users and how often they have logged in, in that file. I leave the writing of that script as an exercise to the reader ;-)






                    share|improve this answer



























                      1














                      Matthew Rock's answer is nice as are the other ones but like Matthew points out then the user can change these numbers. One way to circumvent that is to use PAM.



                      I would put the following line in /etc/pam.d/login



                      session optional pam_exec.so /usr/local/bin/someshellscript.sh


                      And in /usr/local/bin/someshellscript.sh you can use variables like $PAM_USER which gives the username. Then in the shellscript you can access a file that is not writable (and perhaps not readable, depends on what you want) to the users and keep tabs on all the users and how often they have logged in, in that file. I leave the writing of that script as an exercise to the reader ;-)






                      share|improve this answer

























                        1












                        1








                        1







                        Matthew Rock's answer is nice as are the other ones but like Matthew points out then the user can change these numbers. One way to circumvent that is to use PAM.



                        I would put the following line in /etc/pam.d/login



                        session optional pam_exec.so /usr/local/bin/someshellscript.sh


                        And in /usr/local/bin/someshellscript.sh you can use variables like $PAM_USER which gives the username. Then in the shellscript you can access a file that is not writable (and perhaps not readable, depends on what you want) to the users and keep tabs on all the users and how often they have logged in, in that file. I leave the writing of that script as an exercise to the reader ;-)






                        share|improve this answer













                        Matthew Rock's answer is nice as are the other ones but like Matthew points out then the user can change these numbers. One way to circumvent that is to use PAM.



                        I would put the following line in /etc/pam.d/login



                        session optional pam_exec.so /usr/local/bin/someshellscript.sh


                        And in /usr/local/bin/someshellscript.sh you can use variables like $PAM_USER which gives the username. Then in the shellscript you can access a file that is not writable (and perhaps not readable, depends on what you want) to the users and keep tabs on all the users and how often they have logged in, in that file. I leave the writing of that script as an exercise to the reader ;-)







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Mar 5 '16 at 1:05









                        ojsojs

                        656410




                        656410





















                            0














                            Here's one possible hack; add the following lines to your $HOME/.bash_profile (since you tagged bash):



                            NLOGINS=0
                            printf "Hello Mr. This is your %d log inn" $((NLOGINS + 1))
                            sed -i 's/^NLOGINS=.*/NLOGINS='$((NLOGINS + 1))'/' $HOME/.bash_profile


                            Each time you log in, you'll get the printed message and then it will self-update the .bash_profile with the new NLOGINS count.






                            share|improve this answer



























                              0














                              Here's one possible hack; add the following lines to your $HOME/.bash_profile (since you tagged bash):



                              NLOGINS=0
                              printf "Hello Mr. This is your %d log inn" $((NLOGINS + 1))
                              sed -i 's/^NLOGINS=.*/NLOGINS='$((NLOGINS + 1))'/' $HOME/.bash_profile


                              Each time you log in, you'll get the printed message and then it will self-update the .bash_profile with the new NLOGINS count.






                              share|improve this answer

























                                0












                                0








                                0







                                Here's one possible hack; add the following lines to your $HOME/.bash_profile (since you tagged bash):



                                NLOGINS=0
                                printf "Hello Mr. This is your %d log inn" $((NLOGINS + 1))
                                sed -i 's/^NLOGINS=.*/NLOGINS='$((NLOGINS + 1))'/' $HOME/.bash_profile


                                Each time you log in, you'll get the printed message and then it will self-update the .bash_profile with the new NLOGINS count.






                                share|improve this answer













                                Here's one possible hack; add the following lines to your $HOME/.bash_profile (since you tagged bash):



                                NLOGINS=0
                                printf "Hello Mr. This is your %d log inn" $((NLOGINS + 1))
                                sed -i 's/^NLOGINS=.*/NLOGINS='$((NLOGINS + 1))'/' $HOME/.bash_profile


                                Each time you log in, you'll get the printed message and then it will self-update the .bash_profile with the new NLOGINS count.







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Mar 3 '16 at 20:29









                                Jeff SchallerJeff Schaller

                                44k1161142




                                44k1161142





















                                    0














                                    Look at this post https://unix.stackexchange.com/a/350163



                                    Permanent variables using kv-bash functions:



                                    1) Download kv-bash file from github:



                                    git clone https://github.com/damphat/kv-bash.git
                                    cp -ar ./kv-bash/kv-bash /usr/local
                                    chmod +x /usr/local/kv-bash

                                    # Put this line in .bash_profile (optional)
                                    source kv-bash


                                    2) Try



                                    #let try create/modify/delete variable
                                    kvset myEmail john@example.com
                                    kvset myCommand "Very Long Long Long String"

                                    #read the varible
                                    kvget myEmail

                                    #you can also use in another script with $(kvget myEmail)
                                    echo $(kvget myEmail)

                                    #delete variable
                                    kvdel myEmail





                                    share|improve this answer





























                                      0














                                      Look at this post https://unix.stackexchange.com/a/350163



                                      Permanent variables using kv-bash functions:



                                      1) Download kv-bash file from github:



                                      git clone https://github.com/damphat/kv-bash.git
                                      cp -ar ./kv-bash/kv-bash /usr/local
                                      chmod +x /usr/local/kv-bash

                                      # Put this line in .bash_profile (optional)
                                      source kv-bash


                                      2) Try



                                      #let try create/modify/delete variable
                                      kvset myEmail john@example.com
                                      kvset myCommand "Very Long Long Long String"

                                      #read the varible
                                      kvget myEmail

                                      #you can also use in another script with $(kvget myEmail)
                                      echo $(kvget myEmail)

                                      #delete variable
                                      kvdel myEmail





                                      share|improve this answer



























                                        0












                                        0








                                        0







                                        Look at this post https://unix.stackexchange.com/a/350163



                                        Permanent variables using kv-bash functions:



                                        1) Download kv-bash file from github:



                                        git clone https://github.com/damphat/kv-bash.git
                                        cp -ar ./kv-bash/kv-bash /usr/local
                                        chmod +x /usr/local/kv-bash

                                        # Put this line in .bash_profile (optional)
                                        source kv-bash


                                        2) Try



                                        #let try create/modify/delete variable
                                        kvset myEmail john@example.com
                                        kvset myCommand "Very Long Long Long String"

                                        #read the varible
                                        kvget myEmail

                                        #you can also use in another script with $(kvget myEmail)
                                        echo $(kvget myEmail)

                                        #delete variable
                                        kvdel myEmail





                                        share|improve this answer















                                        Look at this post https://unix.stackexchange.com/a/350163



                                        Permanent variables using kv-bash functions:



                                        1) Download kv-bash file from github:



                                        git clone https://github.com/damphat/kv-bash.git
                                        cp -ar ./kv-bash/kv-bash /usr/local
                                        chmod +x /usr/local/kv-bash

                                        # Put this line in .bash_profile (optional)
                                        source kv-bash


                                        2) Try



                                        #let try create/modify/delete variable
                                        kvset myEmail john@example.com
                                        kvset myCommand "Very Long Long Long String"

                                        #read the varible
                                        kvget myEmail

                                        #you can also use in another script with $(kvget myEmail)
                                        echo $(kvget myEmail)

                                        #delete variable
                                        kvdel myEmail






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Apr 13 '17 at 12:36









                                        Community

                                        1




                                        1










                                        answered Mar 9 '17 at 7:25









                                        NizaNiza

                                        1




                                        1





















                                            0














                                            With zsh, you can use the $mapfile special associative array that gives you access to the content of a file as a variable (beware of concurrent access).



                                            #! /bin/zsh -
                                            zmodload zsh/mapfile
                                            echo "Hello Mr. This is your $((++mapfile[$HOME/.number]))th log in"


                                            fish has so-called Universal variables whose content is stored in files in your ~/.config and to which fish serializes access via some IPC mechanism.



                                            #! /bin/fish -
                                            set -U number (math 0$number+1)
                                            echo Hello Mr. This is your $numberth log in





                                            share|improve this answer





























                                              0














                                              With zsh, you can use the $mapfile special associative array that gives you access to the content of a file as a variable (beware of concurrent access).



                                              #! /bin/zsh -
                                              zmodload zsh/mapfile
                                              echo "Hello Mr. This is your $((++mapfile[$HOME/.number]))th log in"


                                              fish has so-called Universal variables whose content is stored in files in your ~/.config and to which fish serializes access via some IPC mechanism.



                                              #! /bin/fish -
                                              set -U number (math 0$number+1)
                                              echo Hello Mr. This is your $numberth log in





                                              share|improve this answer



























                                                0












                                                0








                                                0







                                                With zsh, you can use the $mapfile special associative array that gives you access to the content of a file as a variable (beware of concurrent access).



                                                #! /bin/zsh -
                                                zmodload zsh/mapfile
                                                echo "Hello Mr. This is your $((++mapfile[$HOME/.number]))th log in"


                                                fish has so-called Universal variables whose content is stored in files in your ~/.config and to which fish serializes access via some IPC mechanism.



                                                #! /bin/fish -
                                                set -U number (math 0$number+1)
                                                echo Hello Mr. This is your $numberth log in





                                                share|improve this answer















                                                With zsh, you can use the $mapfile special associative array that gives you access to the content of a file as a variable (beware of concurrent access).



                                                #! /bin/zsh -
                                                zmodload zsh/mapfile
                                                echo "Hello Mr. This is your $((++mapfile[$HOME/.number]))th log in"


                                                fish has so-called Universal variables whose content is stored in files in your ~/.config and to which fish serializes access via some IPC mechanism.



                                                #! /bin/fish -
                                                set -U number (math 0$number+1)
                                                echo Hello Mr. This is your $numberth log in






                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited yesterday

























                                                answered Mar 4 '16 at 23:37









                                                Stéphane ChazelasStéphane Chazelas

                                                311k57589946




                                                311k57589946



























                                                    draft saved

                                                    draft discarded
















































                                                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                                    • 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%2funix.stackexchange.com%2fquestions%2f267460%2fcreating-a-permanent-variable%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







                                                    -bash, shell, shell-script

                                                    Popular posts from this blog

                                                    Frič See also Navigation menuinternal link

                                                    Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant

                                                    fontconfig warning: “/etc/fonts/fonts.conf”, line 100: unknown “element blank” The 2019 Stack Overflow Developer Survey Results Are In“tar: unrecognized option --warning” during 'apt-get install'How to fix Fontconfig errorHow do I figure out which font file is chosen for a system generic font alias?Why are some apt-get-installed fonts being ignored by fc-list, xfontsel, etc?Reload settings in /etc/fonts/conf.dTaking 30 seconds longer to boot after upgrade from jessie to stretchHow to match multiple font names with a single <match> element?Adding a custom font to fontconfigRemoving fonts from fontconfig <match> resultsBroken fonts after upgrading Firefox ESR to latest Firefox