Reply to topic

bash inherits

User avatar jcdole
Registered Member
Posts
39
Karma
0
OS

bash inherits

Sat Nov 09, 2019 3:38 pm
Hello .
Preamble :
Depending of the opensuse distrib
Login shell read :
/etc/profile
/etc/profile.local ( for customization )
eventually for specific programms : /etc/profile.d/
~/.profile for user specificity
Non login shell read :
/etc/bash.bashrc
/etc/bash.bashrc.local ( for customization )
~/.bashrc for user specificity

Note that the login shell also sources the configuration files listed for non login shell.

What I have done :
I have configured /etc/profile to source two files.
One file contains a list of global environment variables
Code: Select all
export NAME=VALUE

The other file contains function definitions
Code: Select all
function MY_FUNCTION () {
........
........
}
export -f MY_FUNCTION


Using logger commands here or there, and reading the journal, I know that the two files are sourced as soon as I log on as a normal user.


The problem :
I have a script that I can start from a shortcut on the user's desktop or from a command line by typing the script name ( including the full path ).
The shortcut is configured to run the file in konsole (kde terminal) and to stay open when finished.
The shortcut is configured to run the file as a normal user.
A -)
I start a session in a terminal using kde konsole.
When I run a bash script from command line all my environnment variables are set and accessible, and all my functions are defined and accessible.
B - )
I start the program by clicking on the desktop shortcut icon.
All my environnment variables are set and accessible, but all my functions are undefined.

My question :
What is the inheritance of a bash script executed from a shortcut on the desktop.
Any help is welcome.
airdrik
Registered Member
Posts
1845
Karma
5
OS

Re: bash inherits

Mon Nov 11, 2019 8:24 pm
Probably depends on what you are using for the EXEC line of the desktop shortcut file. Are you invoking bash to run the command or are you invoking the command directly (possibly using raw sh instead of bash)?

As I understand it, the environment variables are shell agnostic and are inherited directly from parent to child process (unless overridden or blocked), while the functions are bash-specific and would require a bash session in order to be made available. If you aren't explicit about invoking bash it may just be using plain-old sh which would inherit the environment variables but ignore the function declarations. Reviewing bash's man page may provide additional explanation for its behavior.


airdrik, proud to be a member of KDE forums since 2008-Dec.
User avatar jcdole
Registered Member
Posts
39
Karma
0
OS

Re: bash inherits

Wed Apr 29, 2020 10:19 am
airdrik wrote:Probably depends on what you are using for the EXEC line of the desktop shortcut file. Are you invoking bash to run the command or are you invoking the command directly (possibly using raw sh instead of bash)?

Just the full path
[Desktop Entry]
Comment[en_US]=openssh debug mode
Comment=openssh debug mode
Exec=/backup_sys/000_COMMON/SBin/ssh_start_openssh_debug_mode
GenericName[en_US]=openssh debug mode
GenericName=openssh debug mode
Icon=yast-geo-cluster
MimeType=
Name[en_US]=openssh debug mode
Name=openssh debug mode
Path=
StartupNotify=true
Terminal=true
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=


airdrik wrote:Reviewing bash's man page may provide additional explanation for its behavior.

bash's man page ignore every things about kde.
My question mean :
What kde is doing as soon as I double click on the program icon shortcut ?
And why in that case my bash function are not sourced ?

 
Reply to topic

Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], funix, Google [Bot], grahm, henryv, Majestic-12 [Bot], Sogou [Bot], srgmro33, Stephen Leibowitz, Yahoo [Bot]