Why “source” doesn't work in a script run as a Gnome's Desktop Entry?












2














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.shby 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?










share|improve this question
























  • 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


















2














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.shby 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?










share|improve this question
























  • 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
















2












2








2







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.shby 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?










share|improve this question















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.shby 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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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




















  • 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


















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












1 Answer
1






active

oldest

votes


















3














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.






share|improve this answer





















    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    3














    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.






    share|improve this answer


























      3














      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.






      share|improve this answer
























        3












        3








        3






        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        steeldriversteeldriver

        34.8k35184




        34.8k35184






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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

            Mario Kart Wii

            The Binding of Isaac: Rebirth/Afterbirth

            What does “Dominus providebit” mean?