Create temporary empty environment in Linux [closed]

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











up vote
2
down vote

favorite












Is it possible to create a temporary empty environment for a new user in a Shell like Bash or zsh?



I mean like the incognito mode in Chrome which opens an isolated environment in which everything you did gets removed locally (no history, no cookies, no cache, etc). Is such a thing possible in a Linux Shell?







share|improve this question













closed as too broad by Gilles, Jeff Schaller, Stephen Kitt, andcoz, Thomas Dickey Jul 4 at 10:43


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 3




    Create a new ramdisk as /home/$USER on every login and delete it when logout/disconnected.
    – Ipor Sircer
    Jul 3 at 16:57











  • what do you mean by 'environment'? there are environment variables, but also filesystems (/tmp?), network connections, etc.
    – Jeff Schaller
    Jul 3 at 17:03










  • With 'environment' I mean something like an isolated place to do some testing works without interacting with the system but using system resources (binaries, libraries and stuff). Think of it like a temporary user that gets created which has an empty $HOME dir. If you leave the shell, the user gets removed without a trace. The idea with the ramdisk is good but not the solution I am looking for. I want a temporary user which gets created when I need it and gets deleted when I leave the Shell.
    – soner
    Jul 3 at 17:11







  • 1




    What kind of properties are you expecting from that temporary environment? Do you trust the program to play nicely, or do you need to protect against malicious code? What system features does the program need to access — should it be able to see what programs you have installed? Should it be able access the network? Should it be able to see information about your machine (e.g. hardware configuration) that could identify it uniquely? I'm voting this question as too broad because these are completely different problems and you've already had three solutions to three different problems.
    – Gilles
    Jul 3 at 20:29















up vote
2
down vote

favorite












Is it possible to create a temporary empty environment for a new user in a Shell like Bash or zsh?



I mean like the incognito mode in Chrome which opens an isolated environment in which everything you did gets removed locally (no history, no cookies, no cache, etc). Is such a thing possible in a Linux Shell?







share|improve this question













closed as too broad by Gilles, Jeff Schaller, Stephen Kitt, andcoz, Thomas Dickey Jul 4 at 10:43


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 3




    Create a new ramdisk as /home/$USER on every login and delete it when logout/disconnected.
    – Ipor Sircer
    Jul 3 at 16:57











  • what do you mean by 'environment'? there are environment variables, but also filesystems (/tmp?), network connections, etc.
    – Jeff Schaller
    Jul 3 at 17:03










  • With 'environment' I mean something like an isolated place to do some testing works without interacting with the system but using system resources (binaries, libraries and stuff). Think of it like a temporary user that gets created which has an empty $HOME dir. If you leave the shell, the user gets removed without a trace. The idea with the ramdisk is good but not the solution I am looking for. I want a temporary user which gets created when I need it and gets deleted when I leave the Shell.
    – soner
    Jul 3 at 17:11







  • 1




    What kind of properties are you expecting from that temporary environment? Do you trust the program to play nicely, or do you need to protect against malicious code? What system features does the program need to access — should it be able to see what programs you have installed? Should it be able access the network? Should it be able to see information about your machine (e.g. hardware configuration) that could identify it uniquely? I'm voting this question as too broad because these are completely different problems and you've already had three solutions to three different problems.
    – Gilles
    Jul 3 at 20:29













up vote
2
down vote

favorite









up vote
2
down vote

favorite











Is it possible to create a temporary empty environment for a new user in a Shell like Bash or zsh?



I mean like the incognito mode in Chrome which opens an isolated environment in which everything you did gets removed locally (no history, no cookies, no cache, etc). Is such a thing possible in a Linux Shell?







share|improve this question













Is it possible to create a temporary empty environment for a new user in a Shell like Bash or zsh?



I mean like the incognito mode in Chrome which opens an isolated environment in which everything you did gets removed locally (no history, no cookies, no cache, etc). Is such a thing possible in a Linux Shell?









share|improve this question












share|improve this question




share|improve this question








edited Jul 3 at 20:26









Gilles

502k1179891515




502k1179891515









asked Jul 3 at 16:47









soner

563




563




closed as too broad by Gilles, Jeff Schaller, Stephen Kitt, andcoz, Thomas Dickey Jul 4 at 10:43


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as too broad by Gilles, Jeff Schaller, Stephen Kitt, andcoz, Thomas Dickey Jul 4 at 10:43


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 3




    Create a new ramdisk as /home/$USER on every login and delete it when logout/disconnected.
    – Ipor Sircer
    Jul 3 at 16:57











  • what do you mean by 'environment'? there are environment variables, but also filesystems (/tmp?), network connections, etc.
    – Jeff Schaller
    Jul 3 at 17:03










  • With 'environment' I mean something like an isolated place to do some testing works without interacting with the system but using system resources (binaries, libraries and stuff). Think of it like a temporary user that gets created which has an empty $HOME dir. If you leave the shell, the user gets removed without a trace. The idea with the ramdisk is good but not the solution I am looking for. I want a temporary user which gets created when I need it and gets deleted when I leave the Shell.
    – soner
    Jul 3 at 17:11







  • 1




    What kind of properties are you expecting from that temporary environment? Do you trust the program to play nicely, or do you need to protect against malicious code? What system features does the program need to access — should it be able to see what programs you have installed? Should it be able access the network? Should it be able to see information about your machine (e.g. hardware configuration) that could identify it uniquely? I'm voting this question as too broad because these are completely different problems and you've already had three solutions to three different problems.
    – Gilles
    Jul 3 at 20:29













  • 3




    Create a new ramdisk as /home/$USER on every login and delete it when logout/disconnected.
    – Ipor Sircer
    Jul 3 at 16:57











  • what do you mean by 'environment'? there are environment variables, but also filesystems (/tmp?), network connections, etc.
    – Jeff Schaller
    Jul 3 at 17:03










  • With 'environment' I mean something like an isolated place to do some testing works without interacting with the system but using system resources (binaries, libraries and stuff). Think of it like a temporary user that gets created which has an empty $HOME dir. If you leave the shell, the user gets removed without a trace. The idea with the ramdisk is good but not the solution I am looking for. I want a temporary user which gets created when I need it and gets deleted when I leave the Shell.
    – soner
    Jul 3 at 17:11







  • 1




    What kind of properties are you expecting from that temporary environment? Do you trust the program to play nicely, or do you need to protect against malicious code? What system features does the program need to access — should it be able to see what programs you have installed? Should it be able access the network? Should it be able to see information about your machine (e.g. hardware configuration) that could identify it uniquely? I'm voting this question as too broad because these are completely different problems and you've already had three solutions to three different problems.
    – Gilles
    Jul 3 at 20:29








3




3




Create a new ramdisk as /home/$USER on every login and delete it when logout/disconnected.
– Ipor Sircer
Jul 3 at 16:57





Create a new ramdisk as /home/$USER on every login and delete it when logout/disconnected.
– Ipor Sircer
Jul 3 at 16:57













what do you mean by 'environment'? there are environment variables, but also filesystems (/tmp?), network connections, etc.
– Jeff Schaller
Jul 3 at 17:03




what do you mean by 'environment'? there are environment variables, but also filesystems (/tmp?), network connections, etc.
– Jeff Schaller
Jul 3 at 17:03












With 'environment' I mean something like an isolated place to do some testing works without interacting with the system but using system resources (binaries, libraries and stuff). Think of it like a temporary user that gets created which has an empty $HOME dir. If you leave the shell, the user gets removed without a trace. The idea with the ramdisk is good but not the solution I am looking for. I want a temporary user which gets created when I need it and gets deleted when I leave the Shell.
– soner
Jul 3 at 17:11





With 'environment' I mean something like an isolated place to do some testing works without interacting with the system but using system resources (binaries, libraries and stuff). Think of it like a temporary user that gets created which has an empty $HOME dir. If you leave the shell, the user gets removed without a trace. The idea with the ramdisk is good but not the solution I am looking for. I want a temporary user which gets created when I need it and gets deleted when I leave the Shell.
– soner
Jul 3 at 17:11





1




1




What kind of properties are you expecting from that temporary environment? Do you trust the program to play nicely, or do you need to protect against malicious code? What system features does the program need to access — should it be able to see what programs you have installed? Should it be able access the network? Should it be able to see information about your machine (e.g. hardware configuration) that could identify it uniquely? I'm voting this question as too broad because these are completely different problems and you've already had three solutions to three different problems.
– Gilles
Jul 3 at 20:29





What kind of properties are you expecting from that temporary environment? Do you trust the program to play nicely, or do you need to protect against malicious code? What system features does the program need to access — should it be able to see what programs you have installed? Should it be able access the network? Should it be able to see information about your machine (e.g. hardware configuration) that could identify it uniquely? I'm voting this question as too broad because these are completely different problems and you've already had three solutions to three different problems.
– Gilles
Jul 3 at 20:29











4 Answers
4






active

oldest

votes

















up vote
3
down vote













To just add the obvious (at this point it hasn’t been mentioned), this is one of the intentions of jails/containers/zones, and although it may seem like overkill to the uninitiated (I’m assuming nothing), it’s trivial if one is already using them. (And if one is not using them, attempting to reinvent this wheel will be terribly error-prone.)



In short, create a temp docker instance, do your worst, then remove it afterwards. https://docs.docker.com/get-started/



See also this backgrounder: https://blog.jessfraz.com/post/containers-zones-jails-vms/






share|improve this answer




























    up vote
    1
    down vote













    You can use this if you just want to run the program without your configuration files, but you trust that the program is not malicious and not to try to look outside the box.



    I wrote a little something a while back that sets up a temporary directory and starts a shell with a minimal environment. I use this many times daily to test my solutions to questions for this site.



    https://github.com/kusalananda/shell-toolbox



    FreeBSD users can also use the devel/shell-toolbox port.



    The command is called shell and creates a temporary disposable working directory, optionally pre-populated with the contents of another directory, and starts a shell in it. When the shell session exits, the temporary directory is disposed of (depending on command line flags used).



    This can also be used to start another shell other than the user's login shell.



    It doesn't create a temporary user (as this would require administrative permissions), but it does set the HOME variable to the temporary directory, which means that any references to $HOME or ~ would resolve to the temporary directory and not to the "real home" of the user. It is not a "safe" environment in the sense that the rest of the system is protected, but it provides an interactive shell in a throw-away directory where created files and directories will be cleaned up when finished with minimal impact from your ordinary shell environment.



    Example:



    [box] $ shell -s "$HOME/skel" zsh
    shell: info: Copying /home/kk/skel into /tmp_mfs/shell-zsh.5IAh9F2B
    shell: info: Starting /usr/local/bin/zsh in /tmp_mfs/shell-zsh.5IAh9F2B
    $ ls -a
    . .Xdefaults .cvsrc .mailrc .vimrc
    .. .cshrc .login .profile .zshrc
    $ echo "$HOME"
    /tmp_mfs/shell-zsh.zqHtjz49
    $ env
    HOME=/tmp_mfs/shell-zsh.zqHtjz49
    PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin
    PS1=$
    SHELL=/usr/local/bin/zsh
    TERM=screen
    LOGNAME=kk
    SHLVL=1
    PWD=/tmp_mfs/shell-zsh.zqHtjz49
    OLDPWD=/tmp_mfs/shell-zsh.zqHtjz49
    _=/usr/bin/env
    $ exit
    shell: info: Removing /tmp_mfs/shell-zsh.5IAh9F2B


    It doesn't do chroot or anything fancy like that. It's basically a glorified wrapper around env -i.



    See the shell documentation.






    share|improve this answer






























      up vote
      0
      down vote













      Use a snapshot in a virtual machine.



      1. Create a virtual machine with the needed prerequisites.

      2. Create a snapshot of the VM.

      3. Do any test in your VM.

      4. Restore the snapshot, deleting any modification you did to the system.

      5. Go to 3.





      share|improve this answer




























        up vote
        -1
        down vote













        If all you want a totally clean shell void of all environment variables or aliases, you can spawn a new shell then type:



        $ unalias -a
        $ unset `set|grep '^[A-Z_a-z].*=' |sed 's|=.*$||g'`


        This will pretty much remove everything that can be removed. Of course you'll want to set PS1 to something otherwise you won't be able to tell if you're in a quote or at the command prompt.



        Note: This only applies to bash and zsh.






        share|improve this answer



















        • 1




          This is a seriously complicated and not even correct way of achieving an empty environment. (It can fail if there are variables whose value contains a line break.) Just use env -i /bin/sh.
          – Gilles
          Jul 3 at 20:31










        • line breaks won't matter since it's stripping everything after =. And there is no harm in unsetting a variable that doesn't exist.
          – tk421
          Jul 3 at 20:52











        • Hmm, I think it does work in bash because set escapes newlines. But try it in dash or Busybox sh with an environment variable whose value is a newline followed by A * =.
          – Gilles
          Jul 3 at 21:27










        • Ahh, I only verified it on bash on zsh since that was what the question mentioned.
          – tk421
          Jul 3 at 21:34

















        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        3
        down vote













        To just add the obvious (at this point it hasn’t been mentioned), this is one of the intentions of jails/containers/zones, and although it may seem like overkill to the uninitiated (I’m assuming nothing), it’s trivial if one is already using them. (And if one is not using them, attempting to reinvent this wheel will be terribly error-prone.)



        In short, create a temp docker instance, do your worst, then remove it afterwards. https://docs.docker.com/get-started/



        See also this backgrounder: https://blog.jessfraz.com/post/containers-zones-jails-vms/






        share|improve this answer

























          up vote
          3
          down vote













          To just add the obvious (at this point it hasn’t been mentioned), this is one of the intentions of jails/containers/zones, and although it may seem like overkill to the uninitiated (I’m assuming nothing), it’s trivial if one is already using them. (And if one is not using them, attempting to reinvent this wheel will be terribly error-prone.)



          In short, create a temp docker instance, do your worst, then remove it afterwards. https://docs.docker.com/get-started/



          See also this backgrounder: https://blog.jessfraz.com/post/containers-zones-jails-vms/






          share|improve this answer























            up vote
            3
            down vote










            up vote
            3
            down vote









            To just add the obvious (at this point it hasn’t been mentioned), this is one of the intentions of jails/containers/zones, and although it may seem like overkill to the uninitiated (I’m assuming nothing), it’s trivial if one is already using them. (And if one is not using them, attempting to reinvent this wheel will be terribly error-prone.)



            In short, create a temp docker instance, do your worst, then remove it afterwards. https://docs.docker.com/get-started/



            See also this backgrounder: https://blog.jessfraz.com/post/containers-zones-jails-vms/






            share|improve this answer













            To just add the obvious (at this point it hasn’t been mentioned), this is one of the intentions of jails/containers/zones, and although it may seem like overkill to the uninitiated (I’m assuming nothing), it’s trivial if one is already using them. (And if one is not using them, attempting to reinvent this wheel will be terribly error-prone.)



            In short, create a temp docker instance, do your worst, then remove it afterwards. https://docs.docker.com/get-started/



            See also this backgrounder: https://blog.jessfraz.com/post/containers-zones-jails-vms/







            share|improve this answer













            share|improve this answer



            share|improve this answer











            answered Jul 3 at 20:24









            michael

            582310




            582310






















                up vote
                1
                down vote













                You can use this if you just want to run the program without your configuration files, but you trust that the program is not malicious and not to try to look outside the box.



                I wrote a little something a while back that sets up a temporary directory and starts a shell with a minimal environment. I use this many times daily to test my solutions to questions for this site.



                https://github.com/kusalananda/shell-toolbox



                FreeBSD users can also use the devel/shell-toolbox port.



                The command is called shell and creates a temporary disposable working directory, optionally pre-populated with the contents of another directory, and starts a shell in it. When the shell session exits, the temporary directory is disposed of (depending on command line flags used).



                This can also be used to start another shell other than the user's login shell.



                It doesn't create a temporary user (as this would require administrative permissions), but it does set the HOME variable to the temporary directory, which means that any references to $HOME or ~ would resolve to the temporary directory and not to the "real home" of the user. It is not a "safe" environment in the sense that the rest of the system is protected, but it provides an interactive shell in a throw-away directory where created files and directories will be cleaned up when finished with minimal impact from your ordinary shell environment.



                Example:



                [box] $ shell -s "$HOME/skel" zsh
                shell: info: Copying /home/kk/skel into /tmp_mfs/shell-zsh.5IAh9F2B
                shell: info: Starting /usr/local/bin/zsh in /tmp_mfs/shell-zsh.5IAh9F2B
                $ ls -a
                . .Xdefaults .cvsrc .mailrc .vimrc
                .. .cshrc .login .profile .zshrc
                $ echo "$HOME"
                /tmp_mfs/shell-zsh.zqHtjz49
                $ env
                HOME=/tmp_mfs/shell-zsh.zqHtjz49
                PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin
                PS1=$
                SHELL=/usr/local/bin/zsh
                TERM=screen
                LOGNAME=kk
                SHLVL=1
                PWD=/tmp_mfs/shell-zsh.zqHtjz49
                OLDPWD=/tmp_mfs/shell-zsh.zqHtjz49
                _=/usr/bin/env
                $ exit
                shell: info: Removing /tmp_mfs/shell-zsh.5IAh9F2B


                It doesn't do chroot or anything fancy like that. It's basically a glorified wrapper around env -i.



                See the shell documentation.






                share|improve this answer



























                  up vote
                  1
                  down vote













                  You can use this if you just want to run the program without your configuration files, but you trust that the program is not malicious and not to try to look outside the box.



                  I wrote a little something a while back that sets up a temporary directory and starts a shell with a minimal environment. I use this many times daily to test my solutions to questions for this site.



                  https://github.com/kusalananda/shell-toolbox



                  FreeBSD users can also use the devel/shell-toolbox port.



                  The command is called shell and creates a temporary disposable working directory, optionally pre-populated with the contents of another directory, and starts a shell in it. When the shell session exits, the temporary directory is disposed of (depending on command line flags used).



                  This can also be used to start another shell other than the user's login shell.



                  It doesn't create a temporary user (as this would require administrative permissions), but it does set the HOME variable to the temporary directory, which means that any references to $HOME or ~ would resolve to the temporary directory and not to the "real home" of the user. It is not a "safe" environment in the sense that the rest of the system is protected, but it provides an interactive shell in a throw-away directory where created files and directories will be cleaned up when finished with minimal impact from your ordinary shell environment.



                  Example:



                  [box] $ shell -s "$HOME/skel" zsh
                  shell: info: Copying /home/kk/skel into /tmp_mfs/shell-zsh.5IAh9F2B
                  shell: info: Starting /usr/local/bin/zsh in /tmp_mfs/shell-zsh.5IAh9F2B
                  $ ls -a
                  . .Xdefaults .cvsrc .mailrc .vimrc
                  .. .cshrc .login .profile .zshrc
                  $ echo "$HOME"
                  /tmp_mfs/shell-zsh.zqHtjz49
                  $ env
                  HOME=/tmp_mfs/shell-zsh.zqHtjz49
                  PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin
                  PS1=$
                  SHELL=/usr/local/bin/zsh
                  TERM=screen
                  LOGNAME=kk
                  SHLVL=1
                  PWD=/tmp_mfs/shell-zsh.zqHtjz49
                  OLDPWD=/tmp_mfs/shell-zsh.zqHtjz49
                  _=/usr/bin/env
                  $ exit
                  shell: info: Removing /tmp_mfs/shell-zsh.5IAh9F2B


                  It doesn't do chroot or anything fancy like that. It's basically a glorified wrapper around env -i.



                  See the shell documentation.






                  share|improve this answer

























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    You can use this if you just want to run the program without your configuration files, but you trust that the program is not malicious and not to try to look outside the box.



                    I wrote a little something a while back that sets up a temporary directory and starts a shell with a minimal environment. I use this many times daily to test my solutions to questions for this site.



                    https://github.com/kusalananda/shell-toolbox



                    FreeBSD users can also use the devel/shell-toolbox port.



                    The command is called shell and creates a temporary disposable working directory, optionally pre-populated with the contents of another directory, and starts a shell in it. When the shell session exits, the temporary directory is disposed of (depending on command line flags used).



                    This can also be used to start another shell other than the user's login shell.



                    It doesn't create a temporary user (as this would require administrative permissions), but it does set the HOME variable to the temporary directory, which means that any references to $HOME or ~ would resolve to the temporary directory and not to the "real home" of the user. It is not a "safe" environment in the sense that the rest of the system is protected, but it provides an interactive shell in a throw-away directory where created files and directories will be cleaned up when finished with minimal impact from your ordinary shell environment.



                    Example:



                    [box] $ shell -s "$HOME/skel" zsh
                    shell: info: Copying /home/kk/skel into /tmp_mfs/shell-zsh.5IAh9F2B
                    shell: info: Starting /usr/local/bin/zsh in /tmp_mfs/shell-zsh.5IAh9F2B
                    $ ls -a
                    . .Xdefaults .cvsrc .mailrc .vimrc
                    .. .cshrc .login .profile .zshrc
                    $ echo "$HOME"
                    /tmp_mfs/shell-zsh.zqHtjz49
                    $ env
                    HOME=/tmp_mfs/shell-zsh.zqHtjz49
                    PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin
                    PS1=$
                    SHELL=/usr/local/bin/zsh
                    TERM=screen
                    LOGNAME=kk
                    SHLVL=1
                    PWD=/tmp_mfs/shell-zsh.zqHtjz49
                    OLDPWD=/tmp_mfs/shell-zsh.zqHtjz49
                    _=/usr/bin/env
                    $ exit
                    shell: info: Removing /tmp_mfs/shell-zsh.5IAh9F2B


                    It doesn't do chroot or anything fancy like that. It's basically a glorified wrapper around env -i.



                    See the shell documentation.






                    share|improve this answer















                    You can use this if you just want to run the program without your configuration files, but you trust that the program is not malicious and not to try to look outside the box.



                    I wrote a little something a while back that sets up a temporary directory and starts a shell with a minimal environment. I use this many times daily to test my solutions to questions for this site.



                    https://github.com/kusalananda/shell-toolbox



                    FreeBSD users can also use the devel/shell-toolbox port.



                    The command is called shell and creates a temporary disposable working directory, optionally pre-populated with the contents of another directory, and starts a shell in it. When the shell session exits, the temporary directory is disposed of (depending on command line flags used).



                    This can also be used to start another shell other than the user's login shell.



                    It doesn't create a temporary user (as this would require administrative permissions), but it does set the HOME variable to the temporary directory, which means that any references to $HOME or ~ would resolve to the temporary directory and not to the "real home" of the user. It is not a "safe" environment in the sense that the rest of the system is protected, but it provides an interactive shell in a throw-away directory where created files and directories will be cleaned up when finished with minimal impact from your ordinary shell environment.



                    Example:



                    [box] $ shell -s "$HOME/skel" zsh
                    shell: info: Copying /home/kk/skel into /tmp_mfs/shell-zsh.5IAh9F2B
                    shell: info: Starting /usr/local/bin/zsh in /tmp_mfs/shell-zsh.5IAh9F2B
                    $ ls -a
                    . .Xdefaults .cvsrc .mailrc .vimrc
                    .. .cshrc .login .profile .zshrc
                    $ echo "$HOME"
                    /tmp_mfs/shell-zsh.zqHtjz49
                    $ env
                    HOME=/tmp_mfs/shell-zsh.zqHtjz49
                    PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin
                    PS1=$
                    SHELL=/usr/local/bin/zsh
                    TERM=screen
                    LOGNAME=kk
                    SHLVL=1
                    PWD=/tmp_mfs/shell-zsh.zqHtjz49
                    OLDPWD=/tmp_mfs/shell-zsh.zqHtjz49
                    _=/usr/bin/env
                    $ exit
                    shell: info: Removing /tmp_mfs/shell-zsh.5IAh9F2B


                    It doesn't do chroot or anything fancy like that. It's basically a glorified wrapper around env -i.



                    See the shell documentation.







                    share|improve this answer















                    share|improve this answer



                    share|improve this answer








                    edited Jul 3 at 20:50


























                    answered Jul 3 at 17:59









                    Kusalananda

                    101k13199312




                    101k13199312




















                        up vote
                        0
                        down vote













                        Use a snapshot in a virtual machine.



                        1. Create a virtual machine with the needed prerequisites.

                        2. Create a snapshot of the VM.

                        3. Do any test in your VM.

                        4. Restore the snapshot, deleting any modification you did to the system.

                        5. Go to 3.





                        share|improve this answer

























                          up vote
                          0
                          down vote













                          Use a snapshot in a virtual machine.



                          1. Create a virtual machine with the needed prerequisites.

                          2. Create a snapshot of the VM.

                          3. Do any test in your VM.

                          4. Restore the snapshot, deleting any modification you did to the system.

                          5. Go to 3.





                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            Use a snapshot in a virtual machine.



                            1. Create a virtual machine with the needed prerequisites.

                            2. Create a snapshot of the VM.

                            3. Do any test in your VM.

                            4. Restore the snapshot, deleting any modification you did to the system.

                            5. Go to 3.





                            share|improve this answer













                            Use a snapshot in a virtual machine.



                            1. Create a virtual machine with the needed prerequisites.

                            2. Create a snapshot of the VM.

                            3. Do any test in your VM.

                            4. Restore the snapshot, deleting any modification you did to the system.

                            5. Go to 3.






                            share|improve this answer













                            share|improve this answer



                            share|improve this answer











                            answered Jul 4 at 10:35









                            andcoz

                            11.5k32938




                            11.5k32938




















                                up vote
                                -1
                                down vote













                                If all you want a totally clean shell void of all environment variables or aliases, you can spawn a new shell then type:



                                $ unalias -a
                                $ unset `set|grep '^[A-Z_a-z].*=' |sed 's|=.*$||g'`


                                This will pretty much remove everything that can be removed. Of course you'll want to set PS1 to something otherwise you won't be able to tell if you're in a quote or at the command prompt.



                                Note: This only applies to bash and zsh.






                                share|improve this answer



















                                • 1




                                  This is a seriously complicated and not even correct way of achieving an empty environment. (It can fail if there are variables whose value contains a line break.) Just use env -i /bin/sh.
                                  – Gilles
                                  Jul 3 at 20:31










                                • line breaks won't matter since it's stripping everything after =. And there is no harm in unsetting a variable that doesn't exist.
                                  – tk421
                                  Jul 3 at 20:52











                                • Hmm, I think it does work in bash because set escapes newlines. But try it in dash or Busybox sh with an environment variable whose value is a newline followed by A * =.
                                  – Gilles
                                  Jul 3 at 21:27










                                • Ahh, I only verified it on bash on zsh since that was what the question mentioned.
                                  – tk421
                                  Jul 3 at 21:34














                                up vote
                                -1
                                down vote













                                If all you want a totally clean shell void of all environment variables or aliases, you can spawn a new shell then type:



                                $ unalias -a
                                $ unset `set|grep '^[A-Z_a-z].*=' |sed 's|=.*$||g'`


                                This will pretty much remove everything that can be removed. Of course you'll want to set PS1 to something otherwise you won't be able to tell if you're in a quote or at the command prompt.



                                Note: This only applies to bash and zsh.






                                share|improve this answer



















                                • 1




                                  This is a seriously complicated and not even correct way of achieving an empty environment. (It can fail if there are variables whose value contains a line break.) Just use env -i /bin/sh.
                                  – Gilles
                                  Jul 3 at 20:31










                                • line breaks won't matter since it's stripping everything after =. And there is no harm in unsetting a variable that doesn't exist.
                                  – tk421
                                  Jul 3 at 20:52











                                • Hmm, I think it does work in bash because set escapes newlines. But try it in dash or Busybox sh with an environment variable whose value is a newline followed by A * =.
                                  – Gilles
                                  Jul 3 at 21:27










                                • Ahh, I only verified it on bash on zsh since that was what the question mentioned.
                                  – tk421
                                  Jul 3 at 21:34












                                up vote
                                -1
                                down vote










                                up vote
                                -1
                                down vote









                                If all you want a totally clean shell void of all environment variables or aliases, you can spawn a new shell then type:



                                $ unalias -a
                                $ unset `set|grep '^[A-Z_a-z].*=' |sed 's|=.*$||g'`


                                This will pretty much remove everything that can be removed. Of course you'll want to set PS1 to something otherwise you won't be able to tell if you're in a quote or at the command prompt.



                                Note: This only applies to bash and zsh.






                                share|improve this answer















                                If all you want a totally clean shell void of all environment variables or aliases, you can spawn a new shell then type:



                                $ unalias -a
                                $ unset `set|grep '^[A-Z_a-z].*=' |sed 's|=.*$||g'`


                                This will pretty much remove everything that can be removed. Of course you'll want to set PS1 to something otherwise you won't be able to tell if you're in a quote or at the command prompt.



                                Note: This only applies to bash and zsh.







                                share|improve this answer















                                share|improve this answer



                                share|improve this answer








                                edited Jul 5 at 13:15


























                                answered Jul 3 at 18:46









                                tk421

                                2168




                                2168







                                • 1




                                  This is a seriously complicated and not even correct way of achieving an empty environment. (It can fail if there are variables whose value contains a line break.) Just use env -i /bin/sh.
                                  – Gilles
                                  Jul 3 at 20:31










                                • line breaks won't matter since it's stripping everything after =. And there is no harm in unsetting a variable that doesn't exist.
                                  – tk421
                                  Jul 3 at 20:52











                                • Hmm, I think it does work in bash because set escapes newlines. But try it in dash or Busybox sh with an environment variable whose value is a newline followed by A * =.
                                  – Gilles
                                  Jul 3 at 21:27










                                • Ahh, I only verified it on bash on zsh since that was what the question mentioned.
                                  – tk421
                                  Jul 3 at 21:34












                                • 1




                                  This is a seriously complicated and not even correct way of achieving an empty environment. (It can fail if there are variables whose value contains a line break.) Just use env -i /bin/sh.
                                  – Gilles
                                  Jul 3 at 20:31










                                • line breaks won't matter since it's stripping everything after =. And there is no harm in unsetting a variable that doesn't exist.
                                  – tk421
                                  Jul 3 at 20:52











                                • Hmm, I think it does work in bash because set escapes newlines. But try it in dash or Busybox sh with an environment variable whose value is a newline followed by A * =.
                                  – Gilles
                                  Jul 3 at 21:27










                                • Ahh, I only verified it on bash on zsh since that was what the question mentioned.
                                  – tk421
                                  Jul 3 at 21:34







                                1




                                1




                                This is a seriously complicated and not even correct way of achieving an empty environment. (It can fail if there are variables whose value contains a line break.) Just use env -i /bin/sh.
                                – Gilles
                                Jul 3 at 20:31




                                This is a seriously complicated and not even correct way of achieving an empty environment. (It can fail if there are variables whose value contains a line break.) Just use env -i /bin/sh.
                                – Gilles
                                Jul 3 at 20:31












                                line breaks won't matter since it's stripping everything after =. And there is no harm in unsetting a variable that doesn't exist.
                                – tk421
                                Jul 3 at 20:52





                                line breaks won't matter since it's stripping everything after =. And there is no harm in unsetting a variable that doesn't exist.
                                – tk421
                                Jul 3 at 20:52













                                Hmm, I think it does work in bash because set escapes newlines. But try it in dash or Busybox sh with an environment variable whose value is a newline followed by A * =.
                                – Gilles
                                Jul 3 at 21:27




                                Hmm, I think it does work in bash because set escapes newlines. But try it in dash or Busybox sh with an environment variable whose value is a newline followed by A * =.
                                – Gilles
                                Jul 3 at 21:27












                                Ahh, I only verified it on bash on zsh since that was what the question mentioned.
                                – tk421
                                Jul 3 at 21:34




                                Ahh, I only verified it on bash on zsh since that was what the question mentioned.
                                – tk421
                                Jul 3 at 21:34


                                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?