KDE environment - BASH initialization different behaviour depending from where it is launched

Hello.
This current thread is the following of this one :
https://forums.opensuse.org/showthread.php/538554

In summary I source a script in /etc/profile for wide access. The script contains 80 bash function definitions.
In /etc/bash.bashrc I check if all the functions are defined.
I also perform the same check in $USER/. profile and in $USER/. bashrc
If any functions are not available I use the logger to write a message in system journal.

After log in, reading the journal does not show any errors.

Depending of my configuration I can start a terminal session in three ways :

  1. Application launcher / Favorites / Terminal application
  2. Application launcher / Applications / System / Terminal application
  3. Panel ( Widget ) icon Terminal application

Option 1 is the result of “Add to favorite” from “Application launcher / Applications / System / Terminal application”
Option 3 is the result of “Add to panel (Widget)” from “Application launcher / Applications / System / Terminal application”

Starting a terminal session from Option 1 or Option 2 does not show any errors.
Starting a terminal session from option 3 show an error :

**déc. 22 18:52:20 ASUS-G750JZ** JCD_SYSTEM_COMMON_BIN[4132]: /backup_sys/000_COMMON/Bin/check_export_system_common_function - LIST of ERROR : BEGIN --::  FUNCTION Number : 1 ; Function : abort_because_test ; A_FLAG :  ; DEFINED : FALSE !!! ;  FUNCTION Number : 3 ; Function : array_contains_element ; A_FLAG :  ; DEFINED : FALSE !!! ;  FUNCTION Number : 6 ; Function : ask_YyNn_timeout ; A_FLAG :  ; DEFINED : FALSE !!! ;  FUNCTION Number : 8 ; Function : ask_YyYy ; A_FLAG :  ; DEFINED : FALSE !!! ;  FUNCTION Number : 10 ; Function : config_at_next_reboot ; A_FLAG :  ; DEFINED : FALSE !!! ;  FUNCTION Number : 11 ; Function : confirm_twice ; A_FLAG :  ; DEFINED : FALSE !!! ;  FUNCTION Number : 14 ; Function : create_my_directory_user ; A_FLAG :  ; DEFINED : FALSE !!! ;  FUNCTION Number : 19 ; Function : date2stamp_full ; A_FLAG :  ; DEFINED : FALSE !!! ;  FUNCTION Number : 21 ; Function : deactivate_all_repo ; A_FLAG :  ; DEFINED : FALSE !!! ;  FUNCTION Number : 24 ; Function : file_add_initial_ext_name ; A_FLAG :  ; DEFINED : FALSE !!! ;  FUNCTION Number : 25 ; Function :    {truncked by system logger}
**déc. 22 18:52:20 ASUS-G750JZ** JCD_HOME_USER_STD_BASHRC[4133]: himBH  - /home/user_install/.bashrc - SOURCING DONE : Nb MISSING FUNC : 32  - USER :  user_install
**déc. 22 18:52:20 ASUS-G750JZ** JCD_HOME_USER_STD_BASHRC[4134]: himBH  - /home/user_install/.bashrc -  ¤¤ END ¤¤   - USER :  user_install

Any help is welcome

You can verify on your system…

I would expect that option 2 should launch your terminal directly, and now it launches should be described by its command (you should be able inspect in your menu item properties).

Option 1 should be a shortcut/symlink to option 2 so Option 1 should never be any different than what is described in option 2.

Option 3 is the wildcard which can be anything. Widgets are generally optional, and can be coded a number of different ways… Maybe it launches your terminal completely independently of your other options, maybe it is coded as a symlink like option 1. You’d have to inspect the widget closely or experiment with it to know what it does.

As for any modifications you make…
Of course bashrc modifications generally affect only the logged in User (therefor you’ll find the settings in the User’s home directory) and modifications to /etc/profile, /etc/profile.local or in /etc/profile.d/ will affect your entire system because those locations are read during system bootup, not when you login. If your settings are unexpected, then you’ll have to look at whether your various settings conflict or can harmoniously co-exist.

TSU

I am not completely sure what you are doing there. I normally use “csh” (really “tcsh”) rather than “bash” so I can’t easily check.

Here’s something to try:

In a terminal session, run:


xterm
xterm -ls

Do those give different results?

The difference between them is that the second of those command starts your shell as a login shell, while the first doesn’t. That affects shell startup.

thanks to ‘nrickert’ and ‘tsu’ for answering. I rewrite my question. When you finished leap install you got the application launcher with the tree ‘main/applications/system’ with a konsole starter option. Editing the application launcher, one can see that the command is :

konsole

This is what I called Option 2 for this starter in my thread #1 There is already a konsole starter in the favorite’s tree. Editing the favorite’s konsole starter one can see that the same command is in use.

konsole

This is what I called Option 1 for this starter in my thread #1 Now from the application launcher with a right click, you can add a starter in the panel which is called 'add to panel (Widget) This is what I called Option 3 for this starter in my thread #1 Where to find informations about :

  1. What happens when you start konsole from kickoff ( what program is run, what config file is in use, what is the environment. )
  2. As you cannot edit what is in panel widget what happens when you click on the konsole icon ( what program is run, what config file is in use, what is the environment. )

Any help is welcome. ps : Of course I have read this : https://doc.opensuse.org/documentation/leap/startup/html/book.opensuse.startup/cha-adm-shell.html

Although there is probably KDE documentation for Konsole,
I’d probably prefer simply looking at the contents of the Konsole package (see command below) and inspect any files that are likely configuration files, expecting to see self-documentation as comments

rpm -ql konsole

TSU

As far as I know, all methods of starting “konsole” are pretty much equivalent.

Configuration is at “$HOME/.config/konsolerc” and at “$HOME/.local/share/konsole”.

The environment of process most certainly depends on how it is started - as part of user “session” or as part of systemd user service, simply because then environment is inherited via completely different paths. Whether KDE tries to feed environment of user session to systemd user instance I do not know (GNOME session does it).

I checked the environments of konsoles invoked from the application starter and from the panel. In the latter the definitions from ~/.profile are missing.

Which implies that it is not started as login shell and does not source /etc/profile itself. In this case distinction between process as part of user session and as part of systemd service becomes really important - systemd does not allow function definitions so does not (re-)export them to services:

bor@bor-Latitude-E5450:~/src/systemd$ systemctl --user import-environment 'BASH_FUNC_testfunc%%'
Not a valid environment variable name: BASH_FUNC_testfunc%%
bor@bor-Latitude-E5450:~/src/systemd$ 

And even if name had been accepted, currently systemd does not allow newline in environment variable value.

My findings were premature. The difference in environments actually is aside from the trivial ones:

karl@erlangen:~> diff panel.txt starter.txt 
...
126c126
< _=set
---
> _=MAN_POSIXLY_CORRECT
karl@erlangen:~> 

How to do that ?
I’m interested in this.

I want to understand something.
Depending on my configuration the import of function definitions and environment variables is done in/etc/profile.local
When a user has successfully logged in

  1. /etc/profile.local has been read/source/executed
  2. /etc/bash.bashrc.local has been read/source/executed
  3. ~/. bashrc has been read/source/executed
  4. ~/. profile has been read/source/executed

When I run konsole from apps_starter or from panel,

  1. /etc/bash.bashrc.local has been read/source/executed
  2. ~/. bashrc has been read/source/executed

Since/etc/profile.local is not read/source/executed again, there is no additional duplicate import that systemd could refuse.
Assuming that systemd has the possibility to prevent the transmission of function definition, it is nevertheless true that the problem comes from the difference in launchin from ‘apps_starter’ or from ‘panel’.

I created in ** application starter / apps / utilities** an application ‘COUNT_FUNC’ using this command:

konsole  --profile "my_profile_std"  -e  /my_path/to/my/scripts/count_exported_function

The ‘COUNT_FUNC’ file contains :

env | grep BASH_FUNC | wc -l
echo "Type a key"
read -r MY_TEMP

Then I put ‘COUNT_FUNC’ in my favorites and in panel.

The results are correct from my favorites (81) and wrong from panel (48)
The result is also wrong (48) from dolphin/open terminal then command

/my_path/to/my/scripts/count_exported_function

Any comments is welcome

Hi,

Maybe not related to what you’re looking/asking for but I’m just curios about the value of SHVL on those output. I mean you can just add


echo "$SHVL"

at the bottom of your code

At a best guess is that the D.E. has something to do with that, since you’re launching it via the the desktop icons , If I understood you correctly.

As far as I know, the important difference is whether bash is started as a login shell.

You can set that in the konsole profile, where it lists the command to run. That command probably shows as “/bin/bash”. Change it to “/bin/bash -l” to force it to behave as a login shell.

From app launcher :

user_install@ASUS-G750JZ:~> /backup_sys/000_COMMON/Bin/system_common_function_count_export
81
SHVL: 
Type a key

From panel :

user_install@ASUS-G750JZ-JC:~> /backup_sys/000_COMMON/Bin/system_common_function_count_export
48
SHVL: 
Type a key



I have made new test.

One laptop with leap 15.0 and an older version of my sourced functions ( only 60 functions for 71 KiB ) and an older version of my sourced env var ( for 23 KiB )
One laptop with leap 15.1 and the current version of my sourced functions ( 81 functions for 105 KiB ) and the current version of my sourced env var ( for 24 KiB )

Older version does not show any problems on any computer when launch from App Launcher or from panel.

Current version show problems on any computer when launch from panel (No problem when launch from App launcher).

Any comment is welcome.

In the konsole user profile i have change “/bin/bash” to “/bin/bash -l”

That change nothing for the result of command issue from panel :

From app launcher
Journald


janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12142]: himBH  - /etc/profile.local -  %% BEGIN %%   - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12145]: himBH  - /etc/profile.local -  INTERACTIVE  - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12150]: himBH  - /etc/profile.local - SUCCESS or ALREADY DONE : source /backup_sys/000_COMMON/Bin/system_common_function  - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12154]: himBH  - /etc/profile.local - SUCCESS : source /backup_sys/000_COMMON/Bin/system_common_general_env_var ALREADY DONE  - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12161]: himBH  - /etc/profile.local - NB_FUNC : 81  - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12171]: himBH  - /etc/profile.local -  %% END %%   - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_ETC_BASH_BASHRC_LOCAL[12184]: himBH  - /etc/bash.bashrc.local -  && BEGIN &&   - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_ETC_BASH_BASHRC_LOCAL[12187]: himBH  - /etc/bash.bashrc.local -  INTERACTIVE  - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_ETC_BASH_BASHRC_LOCAL[12194]: himBH  - /etc/bash.bashrc.local - NB_FUNC : 81  - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_ETC_BASH_BASHRC_LOCAL[12197]: himBH  - /etc/bash.bashrc.local -  && END &&   - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_BASHRC[12198]: himBH  - /home/user_install/.bashrc -  ¤¤ BEGIN ¤¤   - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_BASHRC[12199]: himBH  - /home/user_install/.bashrc -  INTERACTIVE  - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_BASHRC[12204]: himBH  - /home/user_install/.bashrc - NB_FUNC : 81  - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_BASHRC[12205]: himBH  - /home/user_install/.bashrc -  ¤¤ END ¤¤   - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_PROFILE[12206]: himBH  - /home/user_install/.profile -  µµ BEGIN µµ   - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_PROFILE[12207]: himBH  - /home/user_install/.profile -  INTERACTIVE  - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_PROFILE[12212]: himBH  - /home/user_install/.profile - NB_FUNC : 81  - USER :  user_install
janv. 06 18:30:59 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_PROFILE[12213]: himBH  - /home/user_install/.profile -  µµ END µµ   - USER :  user_install

Command executed :

user_install@ASUS-G750JZ:~> /backup_sys/000_COMMON/Bin/system_common_function_count_export
81
SHVL: 
Type a key

From panel
Journald


janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12230]: himBH  - /etc/profile.local -  %% BEGIN %%   - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12233]: himBH  - /etc/profile.local -  INTERACTIVE  - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12238]: himBH  - /etc/profile.local - SUCCESS or ALREADY DONE : source /backup_sys/000_COMMON/Bin/system_common_function  - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12242]: himBH  - /etc/profile.local - SUCCESS : source /backup_sys/000_COMMON/Bin/system_common_general_env_var ALREADY DONE  - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12249]: himBH  - /etc/profile.local - NB_FUNC : 48  - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_ETC_PROFILE_LOCAL[12259]: himBH  - /etc/profile.local -  %% END %%   - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_ETC_BASH_BASHRC_LOCAL[12272]: himBH  - /etc/bash.bashrc.local -  && BEGIN &&   - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_ETC_BASH_BASHRC_LOCAL[12275]: himBH  - /etc/bash.bashrc.local -  INTERACTIVE  - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_ETC_BASH_BASHRC_LOCAL[12282]: himBH  - /etc/bash.bashrc.local - NB_FUNC : 48  - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_ETC_BASH_BASHRC_LOCAL[12285]: himBH  - /etc/bash.bashrc.local -  && END &&   - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_BASHRC[12286]: himBH  - /home/user_install/.bashrc -  ¤¤ BEGIN ¤¤   - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_BASHRC[12287]: himBH  - /home/user_install/.bashrc -  INTERACTIVE  - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_BASHRC[12292]: himBH  - /home/user_install/.bashrc - NB_FUNC : 48  - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_BASHRC[12293]: himBH  - /home/user_install/.bashrc -  ¤¤ END ¤¤   - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_PROFILE[12294]: himBH  - /home/user_install/.profile -  µµ BEGIN µµ   - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_PROFILE[12295]: himBH  - /home/user_install/.profile -  INTERACTIVE  - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_PROFILE[12300]: himBH  - /home/user_install/.profile - NB_FUNC : 48  - USER :  user_install
janv. 06 18:31:11 ASUS-G750JZ.my_net.nwk JCD_HOME_USER_STD_PROFILE[12301]: himBH  - /home/user_install/.profile -  µµ END µµ   - USER :  user_install

Command executed :

user_install@ASUS-G750JZ:~> /backup_sys/000_COMMON/Bin/system_common_function_count_export
48
SHVL: 
Type a key

I’ve only the following <simple> principle…

Whether the console is launched in a User context or not.

If not, then only the system environmental variables are applied

/etc/profile
/etc/profile.local
/etc/profile.d/*

If executed in a User’s context, then User-specific environmental variables are also read and combined with the system variables which might in the above locations.
User variables are located in all the easily predictable locations, typically within the User’s /home

But then the original post of this thread didn’t really ask about this, the question actually asked about graphical objects… Widgets which can have almost anything “code behind.”
The graphical object might simply be a shortcut or link to one of the two general fire and directory locations described above.
But, a graphical object might also have special flags, options or even original code, so could launch something completely different or with a special configuration.

In a nutshell,
That’s why you can’t assume anything when you click on something… It’s similar to clicking on an email link and being sent to a phishing site.
If you want to create or launch something specific, just pay attention to the details.

IMO,
TSU

Presently I am starting new tests from the good file with 60 functions. I have added the 21 missing functions without code something like this :

function function_xyz () {
return 0
}

And does not have any problem when starting the test script from the app launcher or from panel or from dolphin/open terminal.

user_install@ASUS-G750JZ:~> /backup_sys/000_COMMON/Bin/system_common_function_count_export
82
SHVL: 
Type a key

user_install@ASUS-G750JZ:~> 

I shall making test by filling the real code in the new functions one/by one.

I will give news as soon as possible