change location of .sqlite_history file

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











up vote
4
down vote

favorite
1












sqlite3 stores command history in .sqlite_history, which is by default created in:



$HOME/.sqlite_history


How can I change this location to somewhere else?



This is possible for example with mysql, where I can define environment variable



MYSQL_HISTFILE=/path/to/whatever/file 


But I could not find any corresponding environment variable for sqlite3



export SQLITE_HISTFILE=/tmp/history 


has no effect. I found a post where somebody asks same question, but no useful answers are given.










share|improve this question



















  • 1




    Request was made to the project at sqlite.1065341.n5.nabble.com/…
    – Ben Creasy
    Sep 12 '16 at 7:45















up vote
4
down vote

favorite
1












sqlite3 stores command history in .sqlite_history, which is by default created in:



$HOME/.sqlite_history


How can I change this location to somewhere else?



This is possible for example with mysql, where I can define environment variable



MYSQL_HISTFILE=/path/to/whatever/file 


But I could not find any corresponding environment variable for sqlite3



export SQLITE_HISTFILE=/tmp/history 


has no effect. I found a post where somebody asks same question, but no useful answers are given.










share|improve this question



















  • 1




    Request was made to the project at sqlite.1065341.n5.nabble.com/…
    – Ben Creasy
    Sep 12 '16 at 7:45













up vote
4
down vote

favorite
1









up vote
4
down vote

favorite
1






1





sqlite3 stores command history in .sqlite_history, which is by default created in:



$HOME/.sqlite_history


How can I change this location to somewhere else?



This is possible for example with mysql, where I can define environment variable



MYSQL_HISTFILE=/path/to/whatever/file 


But I could not find any corresponding environment variable for sqlite3



export SQLITE_HISTFILE=/tmp/history 


has no effect. I found a post where somebody asks same question, but no useful answers are given.










share|improve this question















sqlite3 stores command history in .sqlite_history, which is by default created in:



$HOME/.sqlite_history


How can I change this location to somewhere else?



This is possible for example with mysql, where I can define environment variable



MYSQL_HISTFILE=/path/to/whatever/file 


But I could not find any corresponding environment variable for sqlite3



export SQLITE_HISTFILE=/tmp/history 


has no effect. I found a post where somebody asks same question, but no useful answers are given.







environment-variables home sqlite






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 31 '16 at 6:32









Rahul

8,84412842




8,84412842










asked Aug 31 '16 at 6:28









Martin Vegter

62934117234




62934117234







  • 1




    Request was made to the project at sqlite.1065341.n5.nabble.com/…
    – Ben Creasy
    Sep 12 '16 at 7:45













  • 1




    Request was made to the project at sqlite.1065341.n5.nabble.com/…
    – Ben Creasy
    Sep 12 '16 at 7:45








1




1




Request was made to the project at sqlite.1065341.n5.nabble.com/…
– Ben Creasy
Sep 12 '16 at 7:45





Request was made to the project at sqlite.1065341.n5.nabble.com/…
– Ben Creasy
Sep 12 '16 at 7:45











3 Answers
3






active

oldest

votes

















up vote
5
down vote



accepted










It looks like it's hardcoded in line 5576 in shell.c (version 3.14.1):



sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);


So, to change it, your only option is to edit the source and recompile.






share|improve this answer





























    up vote
    3
    down vote













    To list some of the possible alternatives,



    1. make ~/.sqlite_history into a symbolic link to another file.


    2. simply run HOME=/tmp sqlite3 to have the program save the history in /tmp/.sqlite_history, though this assumes you don't need the real home directory inside the command environment.



    3. edit the binary and replace the string "%s/.sqlite_history", found by Hoov, by another string with the same number of bytes, eg "/tmp/sqlitehistory":



      sed < /usr/bin/sqlite3 's|%s/.sqlite_history|/tmp/sqlitehistory|' >/tmp/sqlite3
      cmp -l /usr/bin/sqlite3 /tmp/sqlite3 # check no extraneous differences
      chmod +x /tmp/sqlite3
      /tmp/sqlite3


    4. use the LD_PRELOAD shim I proposed in an another question to change one filename ("/tmp/adb.log" in that case) to another during an open() call.






    share|improve this answer






















    • Excellent and enlightening answer. I feel ignorant now.
      – Hoov
      Sep 2 '16 at 7:36










    • But in reality, when this situation arises, I usually prefer to follow your answer and rebuild from sources, unless this proves to be too tedious, with too many dependencies etc.
      – meuh
      Sep 2 '16 at 7:53










    • Yes, it think it's the most manageable solution, but your solution three could come in handy when you don't have the source. Saved it to a script.
      – Hoov
      Sep 2 '16 at 8:07










    • Note that in sqlite's case, setting $HOME will not work, since sqlite does not honour that environment variable: it uses only what getpwuid() returns (e.g. from /etc/passwd).
      – ayekat
      Aug 31 '17 at 5:58

















    up vote
    1
    down vote













    As of Oct 10, 2018 it appears that a new variable, $SQLITE_HISTORY, was added to address this.






    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%2f306890%2fchange-location-of-sqlite-history-file%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      5
      down vote



      accepted










      It looks like it's hardcoded in line 5576 in shell.c (version 3.14.1):



      sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);


      So, to change it, your only option is to edit the source and recompile.






      share|improve this answer


























        up vote
        5
        down vote



        accepted










        It looks like it's hardcoded in line 5576 in shell.c (version 3.14.1):



        sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);


        So, to change it, your only option is to edit the source and recompile.






        share|improve this answer
























          up vote
          5
          down vote



          accepted







          up vote
          5
          down vote



          accepted






          It looks like it's hardcoded in line 5576 in shell.c (version 3.14.1):



          sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);


          So, to change it, your only option is to edit the source and recompile.






          share|improve this answer














          It looks like it's hardcoded in line 5576 in shell.c (version 3.14.1):



          sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);


          So, to change it, your only option is to edit the source and recompile.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 31 '16 at 7:52

























          answered Aug 31 '16 at 7:44









          Hoov

          57838




          57838






















              up vote
              3
              down vote













              To list some of the possible alternatives,



              1. make ~/.sqlite_history into a symbolic link to another file.


              2. simply run HOME=/tmp sqlite3 to have the program save the history in /tmp/.sqlite_history, though this assumes you don't need the real home directory inside the command environment.



              3. edit the binary and replace the string "%s/.sqlite_history", found by Hoov, by another string with the same number of bytes, eg "/tmp/sqlitehistory":



                sed < /usr/bin/sqlite3 's|%s/.sqlite_history|/tmp/sqlitehistory|' >/tmp/sqlite3
                cmp -l /usr/bin/sqlite3 /tmp/sqlite3 # check no extraneous differences
                chmod +x /tmp/sqlite3
                /tmp/sqlite3


              4. use the LD_PRELOAD shim I proposed in an another question to change one filename ("/tmp/adb.log" in that case) to another during an open() call.






              share|improve this answer






















              • Excellent and enlightening answer. I feel ignorant now.
                – Hoov
                Sep 2 '16 at 7:36










              • But in reality, when this situation arises, I usually prefer to follow your answer and rebuild from sources, unless this proves to be too tedious, with too many dependencies etc.
                – meuh
                Sep 2 '16 at 7:53










              • Yes, it think it's the most manageable solution, but your solution three could come in handy when you don't have the source. Saved it to a script.
                – Hoov
                Sep 2 '16 at 8:07










              • Note that in sqlite's case, setting $HOME will not work, since sqlite does not honour that environment variable: it uses only what getpwuid() returns (e.g. from /etc/passwd).
                – ayekat
                Aug 31 '17 at 5:58














              up vote
              3
              down vote













              To list some of the possible alternatives,



              1. make ~/.sqlite_history into a symbolic link to another file.


              2. simply run HOME=/tmp sqlite3 to have the program save the history in /tmp/.sqlite_history, though this assumes you don't need the real home directory inside the command environment.



              3. edit the binary and replace the string "%s/.sqlite_history", found by Hoov, by another string with the same number of bytes, eg "/tmp/sqlitehistory":



                sed < /usr/bin/sqlite3 's|%s/.sqlite_history|/tmp/sqlitehistory|' >/tmp/sqlite3
                cmp -l /usr/bin/sqlite3 /tmp/sqlite3 # check no extraneous differences
                chmod +x /tmp/sqlite3
                /tmp/sqlite3


              4. use the LD_PRELOAD shim I proposed in an another question to change one filename ("/tmp/adb.log" in that case) to another during an open() call.






              share|improve this answer






















              • Excellent and enlightening answer. I feel ignorant now.
                – Hoov
                Sep 2 '16 at 7:36










              • But in reality, when this situation arises, I usually prefer to follow your answer and rebuild from sources, unless this proves to be too tedious, with too many dependencies etc.
                – meuh
                Sep 2 '16 at 7:53










              • Yes, it think it's the most manageable solution, but your solution three could come in handy when you don't have the source. Saved it to a script.
                – Hoov
                Sep 2 '16 at 8:07










              • Note that in sqlite's case, setting $HOME will not work, since sqlite does not honour that environment variable: it uses only what getpwuid() returns (e.g. from /etc/passwd).
                – ayekat
                Aug 31 '17 at 5:58












              up vote
              3
              down vote










              up vote
              3
              down vote









              To list some of the possible alternatives,



              1. make ~/.sqlite_history into a symbolic link to another file.


              2. simply run HOME=/tmp sqlite3 to have the program save the history in /tmp/.sqlite_history, though this assumes you don't need the real home directory inside the command environment.



              3. edit the binary and replace the string "%s/.sqlite_history", found by Hoov, by another string with the same number of bytes, eg "/tmp/sqlitehistory":



                sed < /usr/bin/sqlite3 's|%s/.sqlite_history|/tmp/sqlitehistory|' >/tmp/sqlite3
                cmp -l /usr/bin/sqlite3 /tmp/sqlite3 # check no extraneous differences
                chmod +x /tmp/sqlite3
                /tmp/sqlite3


              4. use the LD_PRELOAD shim I proposed in an another question to change one filename ("/tmp/adb.log" in that case) to another during an open() call.






              share|improve this answer














              To list some of the possible alternatives,



              1. make ~/.sqlite_history into a symbolic link to another file.


              2. simply run HOME=/tmp sqlite3 to have the program save the history in /tmp/.sqlite_history, though this assumes you don't need the real home directory inside the command environment.



              3. edit the binary and replace the string "%s/.sqlite_history", found by Hoov, by another string with the same number of bytes, eg "/tmp/sqlitehistory":



                sed < /usr/bin/sqlite3 's|%s/.sqlite_history|/tmp/sqlitehistory|' >/tmp/sqlite3
                cmp -l /usr/bin/sqlite3 /tmp/sqlite3 # check no extraneous differences
                chmod +x /tmp/sqlite3
                /tmp/sqlite3


              4. use the LD_PRELOAD shim I proposed in an another question to change one filename ("/tmp/adb.log" in that case) to another during an open() call.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 13 '17 at 12:36









              Community

              1




              1










              answered Aug 31 '16 at 12:35









              meuh

              31.1k11754




              31.1k11754











              • Excellent and enlightening answer. I feel ignorant now.
                – Hoov
                Sep 2 '16 at 7:36










              • But in reality, when this situation arises, I usually prefer to follow your answer and rebuild from sources, unless this proves to be too tedious, with too many dependencies etc.
                – meuh
                Sep 2 '16 at 7:53










              • Yes, it think it's the most manageable solution, but your solution three could come in handy when you don't have the source. Saved it to a script.
                – Hoov
                Sep 2 '16 at 8:07










              • Note that in sqlite's case, setting $HOME will not work, since sqlite does not honour that environment variable: it uses only what getpwuid() returns (e.g. from /etc/passwd).
                – ayekat
                Aug 31 '17 at 5:58
















              • Excellent and enlightening answer. I feel ignorant now.
                – Hoov
                Sep 2 '16 at 7:36










              • But in reality, when this situation arises, I usually prefer to follow your answer and rebuild from sources, unless this proves to be too tedious, with too many dependencies etc.
                – meuh
                Sep 2 '16 at 7:53










              • Yes, it think it's the most manageable solution, but your solution three could come in handy when you don't have the source. Saved it to a script.
                – Hoov
                Sep 2 '16 at 8:07










              • Note that in sqlite's case, setting $HOME will not work, since sqlite does not honour that environment variable: it uses only what getpwuid() returns (e.g. from /etc/passwd).
                – ayekat
                Aug 31 '17 at 5:58















              Excellent and enlightening answer. I feel ignorant now.
              – Hoov
              Sep 2 '16 at 7:36




              Excellent and enlightening answer. I feel ignorant now.
              – Hoov
              Sep 2 '16 at 7:36












              But in reality, when this situation arises, I usually prefer to follow your answer and rebuild from sources, unless this proves to be too tedious, with too many dependencies etc.
              – meuh
              Sep 2 '16 at 7:53




              But in reality, when this situation arises, I usually prefer to follow your answer and rebuild from sources, unless this proves to be too tedious, with too many dependencies etc.
              – meuh
              Sep 2 '16 at 7:53












              Yes, it think it's the most manageable solution, but your solution three could come in handy when you don't have the source. Saved it to a script.
              – Hoov
              Sep 2 '16 at 8:07




              Yes, it think it's the most manageable solution, but your solution three could come in handy when you don't have the source. Saved it to a script.
              – Hoov
              Sep 2 '16 at 8:07












              Note that in sqlite's case, setting $HOME will not work, since sqlite does not honour that environment variable: it uses only what getpwuid() returns (e.g. from /etc/passwd).
              – ayekat
              Aug 31 '17 at 5:58




              Note that in sqlite's case, setting $HOME will not work, since sqlite does not honour that environment variable: it uses only what getpwuid() returns (e.g. from /etc/passwd).
              – ayekat
              Aug 31 '17 at 5:58










              up vote
              1
              down vote













              As of Oct 10, 2018 it appears that a new variable, $SQLITE_HISTORY, was added to address this.






              share|improve this answer
























                up vote
                1
                down vote













                As of Oct 10, 2018 it appears that a new variable, $SQLITE_HISTORY, was added to address this.






                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  As of Oct 10, 2018 it appears that a new variable, $SQLITE_HISTORY, was added to address this.






                  share|improve this answer












                  As of Oct 10, 2018 it appears that a new variable, $SQLITE_HISTORY, was added to address this.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 26 at 3:14









                  mattmc3

                  1113




                  1113



























                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2f306890%2fchange-location-of-sqlite-history-file%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?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?