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;
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
add a comment |
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
Possible duplicate of How do I get the parent process ID of a given child process?
– WinEunuuchs2Unix
Apr 3 '18 at 10:06
add a comment |
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
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
command-line visual-studio-code
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
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...
New contributor
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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...
New contributor
add a comment |
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...
New contributor
add a comment |
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...
New contributor
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...
New contributor
New contributor
answered 4 hours ago
Daniel ImmsDaniel Imms
1013
1013
New contributor
New contributor
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Possible duplicate of How do I get the parent process ID of a given child process?
– WinEunuuchs2Unix
Apr 3 '18 at 10:06