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

Clash Royale CLAN TAG#URR8PPP up vote
1
down vote
favorite
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 |Â
up vote
1
down vote
favorite
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 at 10:06
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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 at 10:02
MichaelTheSlav
61
61
Possible duplicate of How do I get the parent process ID of a given child process?
â WinEunuuchs2Unix
Apr 3 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 at 10:06
Possible duplicate of How do I get the parent process ID of a given child process?
â WinEunuuchs2Unix
Apr 3 at 10:06
Possible duplicate of How do I get the parent process ID of a given child process?
â WinEunuuchs2Unix
Apr 3 at 10:06
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
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 at 11:37
1
We can omit if/then/fi:pstree -s $$ | grep -wq 'code' && echo true:)
â pa4080
Apr 3 at 19:55
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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 at 11:37
1
We can omit if/then/fi:pstree -s $$ | grep -wq 'code' && echo true:)
â pa4080
Apr 3 at 19:55
add a comment |Â
up vote
1
down vote
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 at 11:37
1
We can omit if/then/fi:pstree -s $$ | grep -wq 'code' && echo true:)
â pa4080
Apr 3 at 19:55
add a comment |Â
up vote
1
down vote
up vote
1
down vote
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 at 10:13
WinEunuuchs2Unix
35.8k759133
35.8k759133
2
To extend this:if pstree -s $$ | grep -Eq '<code>'; then echo started from code; fi
â glenn jackman
Apr 3 at 11:37
1
We can omit if/then/fi:pstree -s $$ | grep -wq 'code' && echo true:)
â pa4080
Apr 3 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 at 11:37
1
We can omit if/then/fi:pstree -s $$ | grep -wq 'code' && echo true:)
â pa4080
Apr 3 at 19:55
2
2
To extend this:
if pstree -s $$ | grep -Eq '<code>'; then echo started from code; fiâ glenn jackman
Apr 3 at 11:37
To extend this:
if pstree -s $$ | grep -Eq '<code>'; then echo started from code; fiâ glenn jackman
Apr 3 at 11:37
1
1
We can omit if/then/fi:
pstree -s $$ | grep -wq 'code' && echo true :)â pa4080
Apr 3 at 19:55
We can omit if/then/fi:
pstree -s $$ | grep -wq 'code' && echo true :)â pa4080
Apr 3 at 19:55
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
Possible duplicate of How do I get the parent process ID of a given child process?
â WinEunuuchs2Unix
Apr 3 at 10:06