Why “source” doesn't work in a script run as a Gnome's Desktop Entry?
I have a desktop entry pointing to IntelliJ IDEA
IDE. I wanted to add . ~/.bashrc
at the beginning of the idea.sh
script that is being executed by Desktop Entry. The point of that is that IDEA wasn't picking up my modified SSH_AUTH_SOCK
env variable, that was defined there. So I added a very simple . ~/.bashrc
at the beginning of idea.sh
, to discover that the sourced code is not being run. Now some details.
In ~/.bashrc
I have this:
# Set GPG TTY
export GPG_TTY=$(tty)
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
# Refresh gpg-agent tty in case user switches into an X session
gpg-connect-agent updatestartuptty /bye >/dev/null
I wanted this to run at the beginning of idea.sh
, but . ~/.bashrc
doesn't work, HOWEVER if I put this exact code directly in the idea.sh
, in the same place, it will work just fine.
Sourcing also works if I run idea.sh
directly in my terminal. It doesn't work only if I run it by using Desktop Entry. The desktop entry in question is /home/luken/.local/share/applications/jetbrains-idea.desktop
:
[Desktop Entry]
Version=1.0
Type=Application
Name=IntelliJ IDEA Ultimate Edition
Icon=/home/luken/Programy/idea-IU-182.4505.22/bin/idea.svg
Exec="/home/luken/Programy/idea-IU-182.4505.22/bin/idea.sh" %f
Comment=Capable and Ergonomic IDE for JVM
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-idea
So to sum this up:
Running idea.sh
in terminal:
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
. ~/.bashrc
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/gnupg/S.gpg-agent.ssh
CORRECT.
Running idea.sh
by using Desktop Entry shortcut:
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
. ~/.bashrc
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/keyring/ssh
INCORRECT.
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
# Set GPG TTY
export GPG_TTY=$(tty)
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
# Refresh gpg-agent tty in case user switches into an X session
gpg-connect-agent updatestartuptty /bye >/dev/null
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/gnupg/S.gpg-agent.ssh
CORRECT.
Anyone have any idea what is going on here or how to debug this?
bash gnome gnome-shell intellij
add a comment |
I have a desktop entry pointing to IntelliJ IDEA
IDE. I wanted to add . ~/.bashrc
at the beginning of the idea.sh
script that is being executed by Desktop Entry. The point of that is that IDEA wasn't picking up my modified SSH_AUTH_SOCK
env variable, that was defined there. So I added a very simple . ~/.bashrc
at the beginning of idea.sh
, to discover that the sourced code is not being run. Now some details.
In ~/.bashrc
I have this:
# Set GPG TTY
export GPG_TTY=$(tty)
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
# Refresh gpg-agent tty in case user switches into an X session
gpg-connect-agent updatestartuptty /bye >/dev/null
I wanted this to run at the beginning of idea.sh
, but . ~/.bashrc
doesn't work, HOWEVER if I put this exact code directly in the idea.sh
, in the same place, it will work just fine.
Sourcing also works if I run idea.sh
directly in my terminal. It doesn't work only if I run it by using Desktop Entry. The desktop entry in question is /home/luken/.local/share/applications/jetbrains-idea.desktop
:
[Desktop Entry]
Version=1.0
Type=Application
Name=IntelliJ IDEA Ultimate Edition
Icon=/home/luken/Programy/idea-IU-182.4505.22/bin/idea.svg
Exec="/home/luken/Programy/idea-IU-182.4505.22/bin/idea.sh" %f
Comment=Capable and Ergonomic IDE for JVM
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-idea
So to sum this up:
Running idea.sh
in terminal:
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
. ~/.bashrc
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/gnupg/S.gpg-agent.ssh
CORRECT.
Running idea.sh
by using Desktop Entry shortcut:
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
. ~/.bashrc
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/keyring/ssh
INCORRECT.
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
# Set GPG TTY
export GPG_TTY=$(tty)
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
# Refresh gpg-agent tty in case user switches into an X session
gpg-connect-agent updatestartuptty /bye >/dev/null
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/gnupg/S.gpg-agent.ssh
CORRECT.
Anyone have any idea what is going on here or how to debug this?
bash gnome gnome-shell intellij
Exec doesn't execute more than one binary. If you want to load environment variables, you need to specify them inline in the way ofVAR="variable" executable
.
– Braiam
2 days ago
But it's executing a single script.source
is part of this script.
– Łukasz Zaroda
2 days ago
@steeldriver Bingo! I cannot belive I missed it (the early return). Post this as an answer. :)
– Łukasz Zaroda
2 days ago
add a comment |
I have a desktop entry pointing to IntelliJ IDEA
IDE. I wanted to add . ~/.bashrc
at the beginning of the idea.sh
script that is being executed by Desktop Entry. The point of that is that IDEA wasn't picking up my modified SSH_AUTH_SOCK
env variable, that was defined there. So I added a very simple . ~/.bashrc
at the beginning of idea.sh
, to discover that the sourced code is not being run. Now some details.
In ~/.bashrc
I have this:
# Set GPG TTY
export GPG_TTY=$(tty)
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
# Refresh gpg-agent tty in case user switches into an X session
gpg-connect-agent updatestartuptty /bye >/dev/null
I wanted this to run at the beginning of idea.sh
, but . ~/.bashrc
doesn't work, HOWEVER if I put this exact code directly in the idea.sh
, in the same place, it will work just fine.
Sourcing also works if I run idea.sh
directly in my terminal. It doesn't work only if I run it by using Desktop Entry. The desktop entry in question is /home/luken/.local/share/applications/jetbrains-idea.desktop
:
[Desktop Entry]
Version=1.0
Type=Application
Name=IntelliJ IDEA Ultimate Edition
Icon=/home/luken/Programy/idea-IU-182.4505.22/bin/idea.svg
Exec="/home/luken/Programy/idea-IU-182.4505.22/bin/idea.sh" %f
Comment=Capable and Ergonomic IDE for JVM
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-idea
So to sum this up:
Running idea.sh
in terminal:
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
. ~/.bashrc
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/gnupg/S.gpg-agent.ssh
CORRECT.
Running idea.sh
by using Desktop Entry shortcut:
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
. ~/.bashrc
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/keyring/ssh
INCORRECT.
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
# Set GPG TTY
export GPG_TTY=$(tty)
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
# Refresh gpg-agent tty in case user switches into an X session
gpg-connect-agent updatestartuptty /bye >/dev/null
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/gnupg/S.gpg-agent.ssh
CORRECT.
Anyone have any idea what is going on here or how to debug this?
bash gnome gnome-shell intellij
I have a desktop entry pointing to IntelliJ IDEA
IDE. I wanted to add . ~/.bashrc
at the beginning of the idea.sh
script that is being executed by Desktop Entry. The point of that is that IDEA wasn't picking up my modified SSH_AUTH_SOCK
env variable, that was defined there. So I added a very simple . ~/.bashrc
at the beginning of idea.sh
, to discover that the sourced code is not being run. Now some details.
In ~/.bashrc
I have this:
# Set GPG TTY
export GPG_TTY=$(tty)
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
# Refresh gpg-agent tty in case user switches into an X session
gpg-connect-agent updatestartuptty /bye >/dev/null
I wanted this to run at the beginning of idea.sh
, but . ~/.bashrc
doesn't work, HOWEVER if I put this exact code directly in the idea.sh
, in the same place, it will work just fine.
Sourcing also works if I run idea.sh
directly in my terminal. It doesn't work only if I run it by using Desktop Entry. The desktop entry in question is /home/luken/.local/share/applications/jetbrains-idea.desktop
:
[Desktop Entry]
Version=1.0
Type=Application
Name=IntelliJ IDEA Ultimate Edition
Icon=/home/luken/Programy/idea-IU-182.4505.22/bin/idea.svg
Exec="/home/luken/Programy/idea-IU-182.4505.22/bin/idea.sh" %f
Comment=Capable and Ergonomic IDE for JVM
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-idea
So to sum this up:
Running idea.sh
in terminal:
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
. ~/.bashrc
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/gnupg/S.gpg-agent.ssh
CORRECT.
Running idea.sh
by using Desktop Entry shortcut:
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
. ~/.bashrc
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/keyring/ssh
INCORRECT.
#!/bin/sh
#
# ---------------------------------------------------------------------
# IntelliJ IDEA startup script.
# ---------------------------------------------------------------------
#
# Set GPG TTY
export GPG_TTY=$(tty)
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
# Refresh gpg-agent tty in case user switches into an X session
gpg-connect-agent updatestartuptty /bye >/dev/null
echo "${SSH_AUTH_SOCK}" > ~/auth.txt
# ...
Content of auth.txt
: /run/user/1000/gnupg/S.gpg-agent.ssh
CORRECT.
Anyone have any idea what is going on here or how to debug this?
bash gnome gnome-shell intellij
bash gnome gnome-shell intellij
edited 2 days ago
Rui F Ribeiro
39.3k1479131
39.3k1479131
asked 2 days ago
Łukasz ZarodaŁukasz Zaroda
1,0752912
1,0752912
Exec doesn't execute more than one binary. If you want to load environment variables, you need to specify them inline in the way ofVAR="variable" executable
.
– Braiam
2 days ago
But it's executing a single script.source
is part of this script.
– Łukasz Zaroda
2 days ago
@steeldriver Bingo! I cannot belive I missed it (the early return). Post this as an answer. :)
– Łukasz Zaroda
2 days ago
add a comment |
Exec doesn't execute more than one binary. If you want to load environment variables, you need to specify them inline in the way ofVAR="variable" executable
.
– Braiam
2 days ago
But it's executing a single script.source
is part of this script.
– Łukasz Zaroda
2 days ago
@steeldriver Bingo! I cannot belive I missed it (the early return). Post this as an answer. :)
– Łukasz Zaroda
2 days ago
Exec doesn't execute more than one binary. If you want to load environment variables, you need to specify them inline in the way of
VAR="variable" executable
.– Braiam
2 days ago
Exec doesn't execute more than one binary. If you want to load environment variables, you need to specify them inline in the way of
VAR="variable" executable
.– Braiam
2 days ago
But it's executing a single script.
source
is part of this script.– Łukasz Zaroda
2 days ago
But it's executing a single script.
source
is part of this script.– Łukasz Zaroda
2 days ago
@steeldriver Bingo! I cannot belive I missed it (the early return). Post this as an answer. :)
– Łukasz Zaroda
2 days ago
@steeldriver Bingo! I cannot belive I missed it (the early return). Post this as an answer. :)
– Łukasz Zaroda
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
Your ~/.bashrc
file likely checks whether the shell that it is being sourced into is interactive or not, and in the latter case is returning before completing the instructions in question.
For example, the default ~/.bashrc
in Ubuntu systems has the following code near the top:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
Also be aware that on some systems, /bin/sh
may be a shell other than bash
(for example, the dash
shell) which may not support all of the features of your ~/.bashrc
file.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2funix.stackexchange.com%2fquestions%2f492653%2fwhy-source-doesnt-work-in-a-script-run-as-a-gnomes-desktop-entry%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your ~/.bashrc
file likely checks whether the shell that it is being sourced into is interactive or not, and in the latter case is returning before completing the instructions in question.
For example, the default ~/.bashrc
in Ubuntu systems has the following code near the top:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
Also be aware that on some systems, /bin/sh
may be a shell other than bash
(for example, the dash
shell) which may not support all of the features of your ~/.bashrc
file.
add a comment |
Your ~/.bashrc
file likely checks whether the shell that it is being sourced into is interactive or not, and in the latter case is returning before completing the instructions in question.
For example, the default ~/.bashrc
in Ubuntu systems has the following code near the top:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
Also be aware that on some systems, /bin/sh
may be a shell other than bash
(for example, the dash
shell) which may not support all of the features of your ~/.bashrc
file.
add a comment |
Your ~/.bashrc
file likely checks whether the shell that it is being sourced into is interactive or not, and in the latter case is returning before completing the instructions in question.
For example, the default ~/.bashrc
in Ubuntu systems has the following code near the top:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
Also be aware that on some systems, /bin/sh
may be a shell other than bash
(for example, the dash
shell) which may not support all of the features of your ~/.bashrc
file.
Your ~/.bashrc
file likely checks whether the shell that it is being sourced into is interactive or not, and in the latter case is returning before completing the instructions in question.
For example, the default ~/.bashrc
in Ubuntu systems has the following code near the top:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
Also be aware that on some systems, /bin/sh
may be a shell other than bash
(for example, the dash
shell) which may not support all of the features of your ~/.bashrc
file.
answered 2 days ago
steeldriversteeldriver
34.8k35184
34.8k35184
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2funix.stackexchange.com%2fquestions%2f492653%2fwhy-source-doesnt-work-in-a-script-run-as-a-gnomes-desktop-entry%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
Exec doesn't execute more than one binary. If you want to load environment variables, you need to specify them inline in the way of
VAR="variable" executable
.– Braiam
2 days ago
But it's executing a single script.
source
is part of this script.– Łukasz Zaroda
2 days ago
@steeldriver Bingo! I cannot belive I missed it (the early return). Post this as an answer. :)
– Łukasz Zaroda
2 days ago