Can I check if the terminal was started by Visual Studio Code? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How do I get the parent process ID of a given child process?Open a terminal a run a program on it automatically when the session startsI messed up the ~/.bashrc file and now terminal doesn't open ubuntu 16.04How To Open Visual Studio Code Using TerminalUninstall Visual Studio Code 32bitWindows Subsystem Linux VSCode pathVisual Studio Code sometimes wont loadCan't use go in Visual Studio Code terminalCannot open Visual Studio CodeVisual studio code can't runHow do I show the terminal after a script is executed at startup?

Is there a documented rationale why the House Ways and Means chairman can demand tax info?

What causes the vertical darker bands in my photo?

Do I really need recursive chmod to restrict access to a folder?

Is 1 ppb equal to 1 μg/kg?

Output the ŋarâþ crîþ alphabet song without using (m)any letters

If Jon Snow became King of the Seven Kingdoms what would his regnal number be?

What is a Meta algorithm?

3 doors, three guards, one stone

How to draw this diagram using TikZ package?

What is this single-engine low-wing propeller plane?

Does surprise arrest existing movement?

Can a non-EU citizen traveling with me come with me through the EU passport line?

Why was the term "discrete" used in discrete logarithm?

Antler Helmet: Can it work?

Should I use Javascript Classes or Apex Classes in Lightning Web Components?

What are the pros and cons of Aerospike nosecones?

Can Pao de Queijo, and similar foods, be kosher for Passover?

IndentationError when pasting code in Python 3 interpreter mode

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

Does polymorph use a PC’s CR or its level?

What are 'alternative tunings' of a guitar and why would you use them? Doesn't it make it more difficult to play?

Is it possible to boil a liquid by just mixing many immiscible liquids together?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

Sorting numerically



Can I check if the terminal was started by Visual Studio Code?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How do I get the parent process ID of a given child process?Open a terminal a run a program on it automatically when the session startsI messed up the ~/.bashrc file and now terminal doesn't open ubuntu 16.04How To Open Visual Studio Code Using TerminalUninstall Visual Studio Code 32bitWindows Subsystem Linux VSCode pathVisual Studio Code sometimes wont loadCan't use go in Visual Studio Code terminalCannot open Visual Studio CodeVisual studio code can't runHow do I show the terminal after a script is executed at startup?



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








1















I have a script which runs whenever I open the terminal (I put the command in .bashrc). Now when I open Visual Studio Code the script is obviously also executed in the internal terminal therein. I don‘t want this to happen. Is there any way to detect whether a terminal instance was started by VSCode so I can prevent the script from executing in that case? (I use bash)



Sorry if this is a dumb question, I am still fairly new to Linux and bash.










share|improve this question






















  • Possible duplicate of How do I get the parent process ID of a given child process?

    – WinEunuuchs2Unix
    Apr 3 '18 at 10:06

















1















I have a script which runs whenever I open the terminal (I put the command in .bashrc). Now when I open Visual Studio Code the script is obviously also executed in the internal terminal therein. I don‘t want this to happen. Is there any way to detect whether a terminal instance was started by VSCode so I can prevent the script from executing in that case? (I use bash)



Sorry if this is a dumb question, I am still fairly new to Linux and bash.










share|improve this question






















  • Possible duplicate of How do I get the parent process ID of a given child process?

    – WinEunuuchs2Unix
    Apr 3 '18 at 10:06













1












1








1


1






I have a script which runs whenever I open the terminal (I put the command in .bashrc). Now when I open Visual Studio Code the script is obviously also executed in the internal terminal therein. I don‘t want this to happen. Is there any way to detect whether a terminal instance was started by VSCode so I can prevent the script from executing in that case? (I use bash)



Sorry if this is a dumb question, I am still fairly new to Linux and bash.










share|improve this question














I have a script which runs whenever I open the terminal (I put the command in .bashrc). Now when I open Visual Studio Code the script is obviously also executed in the internal terminal therein. I don‘t want this to happen. Is there any way to detect whether a terminal instance was started by VSCode so I can prevent the script from executing in that case? (I use bash)



Sorry if this is a dumb question, I am still fairly new to Linux and bash.







command-line visual-studio-code






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 3 '18 at 10:02









MichaelTheSlavMichaelTheSlav

61




61












  • Possible duplicate of How do I get the parent process ID of a given child process?

    – WinEunuuchs2Unix
    Apr 3 '18 at 10:06

















  • Possible duplicate of How do I get the parent process ID of a given child process?

    – WinEunuuchs2Unix
    Apr 3 '18 at 10:06
















Possible duplicate of How do I get the parent process ID of a given child process?

– WinEunuuchs2Unix
Apr 3 '18 at 10:06





Possible duplicate of How do I get the parent process ID of a given child process?

– WinEunuuchs2Unix
Apr 3 '18 at 10:06










2 Answers
2






active

oldest

votes


















1














Using this potentially duplicate answer: https://askubuntu.com/a/1012277/307523



rick@alien:~$ echo $$
25119
───────────────────────────────────────────────────────────────────────────────────────────
rick@alien:~$ pstree -aps $$
systemd,1 splash fastboot kaslr
└─lightdm,1026
└─lightdm,1294 --session-child 12 19
└─upstart,1838 --user
└─gnome-terminal-,25109
└─bash,25119
└─pstree,5696 -aps 25119


The environment variable $$ returns the current running processes PID (Process ID) which is the bash terminal.



The pstree command shows the entire "tree" of commands called.






share|improve this answer


















  • 2





    To extend this: if pstree -s $$ | grep -Eq '<code>'; then echo started from code; fi

    – glenn jackman
    Apr 3 '18 at 11:37






  • 1





    We can omit if/then/fi: pstree -s $$ | grep -wq 'code' && echo true :)

    – pa4080
    Apr 3 '18 at 19:55


















0














VS Code sets the standard environment variable TERM_PROGRAM in the terminal's environment to indicate what launched it, so you can solve your problem using this without needing to parse the process tree:



if [[ "$OSTYPE" == "vscode" ]]; then
exit 0
fi

# Rest of script...





share|improve this answer








New contributor




Daniel Imms is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    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: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2faskubuntu.com%2fquestions%2f1021554%2fcan-i-check-if-the-terminal-was-started-by-visual-studio-code%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Using this potentially duplicate answer: https://askubuntu.com/a/1012277/307523



    rick@alien:~$ echo $$
    25119
    ───────────────────────────────────────────────────────────────────────────────────────────
    rick@alien:~$ pstree -aps $$
    systemd,1 splash fastboot kaslr
    └─lightdm,1026
    └─lightdm,1294 --session-child 12 19
    └─upstart,1838 --user
    └─gnome-terminal-,25109
    └─bash,25119
    └─pstree,5696 -aps 25119


    The environment variable $$ returns the current running processes PID (Process ID) which is the bash terminal.



    The pstree command shows the entire "tree" of commands called.






    share|improve this answer


















    • 2





      To extend this: if pstree -s $$ | grep -Eq '<code>'; then echo started from code; fi

      – glenn jackman
      Apr 3 '18 at 11:37






    • 1





      We can omit if/then/fi: pstree -s $$ | grep -wq 'code' && echo true :)

      – pa4080
      Apr 3 '18 at 19:55















    1














    Using this potentially duplicate answer: https://askubuntu.com/a/1012277/307523



    rick@alien:~$ echo $$
    25119
    ───────────────────────────────────────────────────────────────────────────────────────────
    rick@alien:~$ pstree -aps $$
    systemd,1 splash fastboot kaslr
    └─lightdm,1026
    └─lightdm,1294 --session-child 12 19
    └─upstart,1838 --user
    └─gnome-terminal-,25109
    └─bash,25119
    └─pstree,5696 -aps 25119


    The environment variable $$ returns the current running processes PID (Process ID) which is the bash terminal.



    The pstree command shows the entire "tree" of commands called.






    share|improve this answer


















    • 2





      To extend this: if pstree -s $$ | grep -Eq '<code>'; then echo started from code; fi

      – glenn jackman
      Apr 3 '18 at 11:37






    • 1





      We can omit if/then/fi: pstree -s $$ | grep -wq 'code' && echo true :)

      – pa4080
      Apr 3 '18 at 19:55













    1












    1








    1







    Using this potentially duplicate answer: https://askubuntu.com/a/1012277/307523



    rick@alien:~$ echo $$
    25119
    ───────────────────────────────────────────────────────────────────────────────────────────
    rick@alien:~$ pstree -aps $$
    systemd,1 splash fastboot kaslr
    └─lightdm,1026
    └─lightdm,1294 --session-child 12 19
    └─upstart,1838 --user
    └─gnome-terminal-,25109
    └─bash,25119
    └─pstree,5696 -aps 25119


    The environment variable $$ returns the current running processes PID (Process ID) which is the bash terminal.



    The pstree command shows the entire "tree" of commands called.






    share|improve this answer













    Using this potentially duplicate answer: https://askubuntu.com/a/1012277/307523



    rick@alien:~$ echo $$
    25119
    ───────────────────────────────────────────────────────────────────────────────────────────
    rick@alien:~$ pstree -aps $$
    systemd,1 splash fastboot kaslr
    └─lightdm,1026
    └─lightdm,1294 --session-child 12 19
    └─upstart,1838 --user
    └─gnome-terminal-,25109
    └─bash,25119
    └─pstree,5696 -aps 25119


    The environment variable $$ returns the current running processes PID (Process ID) which is the bash terminal.



    The pstree command shows the entire "tree" of commands called.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 3 '18 at 10:13









    WinEunuuchs2UnixWinEunuuchs2Unix

    48.1k1194186




    48.1k1194186







    • 2





      To extend this: if pstree -s $$ | grep -Eq '<code>'; then echo started from code; fi

      – glenn jackman
      Apr 3 '18 at 11:37






    • 1





      We can omit if/then/fi: pstree -s $$ | grep -wq 'code' && echo true :)

      – pa4080
      Apr 3 '18 at 19:55












    • 2





      To extend this: if pstree -s $$ | grep -Eq '<code>'; then echo started from code; fi

      – glenn jackman
      Apr 3 '18 at 11:37






    • 1





      We can omit if/then/fi: pstree -s $$ | grep -wq 'code' && echo true :)

      – pa4080
      Apr 3 '18 at 19:55







    2




    2





    To extend this: if pstree -s $$ | grep -Eq '<code>'; then echo started from code; fi

    – glenn jackman
    Apr 3 '18 at 11:37





    To extend this: if pstree -s $$ | grep -Eq '<code>'; then echo started from code; fi

    – glenn jackman
    Apr 3 '18 at 11:37




    1




    1





    We can omit if/then/fi: pstree -s $$ | grep -wq 'code' && echo true :)

    – pa4080
    Apr 3 '18 at 19:55





    We can omit if/then/fi: pstree -s $$ | grep -wq 'code' && echo true :)

    – pa4080
    Apr 3 '18 at 19:55













    0














    VS Code sets the standard environment variable TERM_PROGRAM in the terminal's environment to indicate what launched it, so you can solve your problem using this without needing to parse the process tree:



    if [[ "$OSTYPE" == "vscode" ]]; then
    exit 0
    fi

    # Rest of script...





    share|improve this answer








    New contributor




    Daniel Imms is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0














      VS Code sets the standard environment variable TERM_PROGRAM in the terminal's environment to indicate what launched it, so you can solve your problem using this without needing to parse the process tree:



      if [[ "$OSTYPE" == "vscode" ]]; then
      exit 0
      fi

      # Rest of script...





      share|improve this answer








      New contributor




      Daniel Imms is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        0












        0








        0







        VS Code sets the standard environment variable TERM_PROGRAM in the terminal's environment to indicate what launched it, so you can solve your problem using this without needing to parse the process tree:



        if [[ "$OSTYPE" == "vscode" ]]; then
        exit 0
        fi

        # Rest of script...





        share|improve this answer








        New contributor




        Daniel Imms is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        VS Code sets the standard environment variable TERM_PROGRAM in the terminal's environment to indicate what launched it, so you can solve your problem using this without needing to parse the process tree:



        if [[ "$OSTYPE" == "vscode" ]]; then
        exit 0
        fi

        # Rest of script...






        share|improve this answer








        New contributor




        Daniel Imms is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        Daniel Imms is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 4 hours ago









        Daniel ImmsDaniel Imms

        1013




        1013




        New contributor




        Daniel Imms is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Daniel Imms is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Daniel Imms is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Ask Ubuntu!


            • 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%2faskubuntu.com%2fquestions%2f1021554%2fcan-i-check-if-the-terminal-was-started-by-visual-studio-code%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

            Möglingen Índice Localización Historia Demografía Referencias Enlaces externos Menú de navegación48°53′18″N 9°07′45″E / 48.888333333333, 9.129166666666748°53′18″N 9°07′45″E / 48.888333333333, 9.1291666666667Sitio web oficial Mapa de Möglingen«Gemeinden in Deutschland nach Fläche, Bevölkerung und Postleitzahl am 30.09.2016»Möglingen

            Virtualbox - Configuration error: Querying “UUID” failed (VERR_CFGM_VALUE_NOT_FOUND)“VERR_SUPLIB_WORLD_WRITABLE” error when trying to installing OS in virtualboxVirtual Box Kernel errorFailed to open a seesion for the virtual machineFailed to open a session for the virtual machineUbuntu 14.04 LTS Virtualbox errorcan't use VM VirtualBoxusing virtualboxI can't run Linux-64 Bit on VirtualBoxUnable to insert the virtual optical disk (VBoxguestaddition) in virtual machine for ubuntu server in win 10VirtuaBox in Ubuntu 18.04 Issues with Win10.ISO Installation

            Antonio De Lisio Carrera Referencias Menú de navegación«Caracas: evolución relacional multipleja»«Cuando los gobiernos subestiman a las localidades: L a Iniciativa para la Integración de la Infraestructura Regional Suramericana (IIRSA) en la frontera Colombo-Venezolana»«Maestría en Planificación Integral del Ambiente»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»«Conózcanos»«Caracas: evolución relacional multipleja»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»