KDE - kde link to script does not return expected result.

here is a script in folder “/backup_sys/000_COMMON/Bin/test_system_common_function_exists”
File mode is ‘rwxr-xr-t’

    if  "$(LC_ALL=C type -t ok_to_do_task)" = function ] ; then
        echo "system_common_function sourced"
        echo "! ! ! ERROR : system_common_function not sourced"

I have a desktop file in desktop user folder.

[Desktop Entry]
Comment[en_US]=system common function exists
Comment=system common function exists
GenericName[en_US]=system common function exists
GenericName=system common function exists
Name[en_US]=system common function exists
Name=system common function exists

When I click on the desktop icon I got :

! ! ! ERROR : system_common_function not sourced

When I type the command within a konsole I got the success message.

user_install@ASUS-G750JZ:~> /backup_sys/000_COMMON/Bin/test_system_common_function_exists

system_common_function exists

Any help is welcome.

When you typed the command in a console bash session, you apparently have defined the function ok_to_do_task earlier in that session. In the desktop file you show, there is nothing that makes me think that the function is defined and the computer confirms this.

BTW can you please copy past commands together with the output you provide, thus not
“here is a script in folder “/backup_sys/000_COMMON/Bin/test_system_common_function_exists”” and then the output in a CODE section, but the command included:

cat /backup_sys/000_COMMON/Bin/test_system_common_function_exists
if  "$(LC_ALL=C type -t ok_to_do_task)" = function ] ; then

and not "File mode is ‘rwxr-xr-t’, but

ls -l /backup_sys/000_COMMON/Bin/test_system_common_function_exists

Then we can exactly see what produced what and it will increase the thustworthyness of what you post enormous.


I have forgot to tell how functions and env vars are set.
They are sourced from /etc/profile.local
/etc/profile.local : https://paste.opensuse.org/40498630

journald : https://paste.opensuse.org/81438424

I have modified my test script.
I test first in each sourced files if a typical env variable is set with the correct value; then after I test if a typical function exists…
When I click on the desktop icon of the test file I got the following result :
The variables are set with the correct value ( one file with value = 123456, the other one with value = 128 )
The functions are not defined ( test return null )

Test script : https://paste.opensuse.org/68525047

Screen log - 1 : https://paste.opensuse.org/98459223

When I open a new konsole session, nothing has changed. /etc/bash.bashrc.local show that files are already sourced.

/etc/bash.bashrc.local : https://paste.opensuse.org/79240499

journald - 2 : https://paste.opensuse.org/95333496

When I type the name of the script in that new session there is no error, functions and variables are defined :

Screen log - 2 : https://paste.opensuse.org/47639559

Any help is welcome

I am very sorry, but trying to read and understand the many rather long scripts and interpreting what they might do and what you think they should do will take a bit too much of my time.

Aren’t you able to reduce this to a small case that illustrates your problem “KDE - kde link to script does not return expected result.”?

As you are referencing to changes in /etc/profile.local, I hope you are aware that you then change the profile of ALL your users. I hope they are glad with that.

Also as it maybe that you are trying to say that settings in the profile are not honoured in a script that is started from a Desktop icon, I can only suggest that you study in what cases the profile is used by the shell.

And on a more general scale, I am afraid that this is another case of http://www.catb.org/~esr/faqs/smart-questions.html#goal because I have realy no idea what you are trying to achieve,

Ok I simplify the question

Given a normal user ( not root ).
Given a bash script without the need of elevated privilege.
The script cannot be more simpler than testing if a function exists using

type -t  some_function_name


typeset -f some_function_name

This script can be started either from command line


or by clicking on an icon on the user’s desktop.
The result is correct from command line (success), and incorrect from desktop (failure).

By the way, the script compare also if an environment variable have the wright value.
In both case ( from command line or from desktop ) the script give the correct result (success).

But in any case variables and functions has been exported by sourcing files in /etc/profile.local before the user start the test script.
It seems that the session environment created when running the desktop file (when clicking on the desktop icon) is different from the session environment started from konsole (when cliking on the konsole icon in the application launcher.)

Sorry but I cannot be more brief.
Sory also for my English which is not my mother language.

When running the test file from the desktop icon, Here is the result of “env | grep BASH_FUNC”


**BASH_FUNC_message_end_script%%=() {  local -a L_ARRAY;
BASH_FUNC_type_a_key_to_continue_timeout%%=() {  local L_TIMEOUT="$1";

From command line :

user_install@ASUS-G750JZ-JC-USB:~> env | grep BASH_FUNC
**BASH_FUNC_message_end_script%%=() {  local -a L_ARRAY;
BASH_FUNC_type_a_key_to_continue_timeout%%=() {  local L_TIMEOUT="$1";
**BASH_FUNC_source_common%%=() {  local -i L_ERR_CODE=112;
BASH_FUNC_message_begin_script%%=() {  local -a L_ARRAY;
BASH_FUNC_date2stamp%%=() {  date --date "$1" +%Y-%m-%d
BASH_FUNC_my_get_salt%%=() {  date --date "$1" +%s%N
BASH_FUNC_yes_or_not_confirm%%=() {  local -i RETURN_CODE=1;
BASH_FUNC_get_operator_input2%%=() {  local -i L_FLAG=0 L_RETURN_CODE=$E_BAD_EXEC;
BASH_FUNC_get_subpath_tail%%=() {  echo "$1" | rev | cut -d"/" -f1-$2 | rev
BASH_FUNC_main_repositories_exists%%=() {  local -a L_ARRAY_MAIN_REPOS;
BASH_FUNC_message_warning%%=() {  local -a L_ARRAY;
BASH_FUNC_get_last_word_from_string%%=() {  local LOCAL_STRING="";
BASH_FUNC_print_if_debug_on%%=() {  local -i L_DEBUG;
BASH_FUNC_stop_or_continue%%=() {  local L_REPLY=" ";
BASH_FUNC_is_running_in_vm%%=() {  local -i MY_FLAG=0;
BASH_FUNC_get_operator_input%%=() {  local -i L_FLAG=0 L_RETURN_CODE=$E_BAD_EXEC;
BASH_FUNC_systemd_unit_exists%%=() {  local __resultvar=$1;
BASH_FUNC_create_encrypted_password%%=() {  local -i L_LEN_SALT=0 L_OFFSET=0 L_FLAG=1;
BASH_FUNC_debug_stop_or_continue%%=() {  local L_REPLY="" L_PARAM1=" " L_CAT_FILE1=" " L_CAT_FILE2=" ";
BASH_FUNC_create_user%%=() {  declare -i L_ERREUR_CODE=0;
BASH_FUNC_trim_string%%=() {  sed 's/^ *//;s/ *$//'
BASH_FUNC_my_bash_eval%%=() {  local L_SOME_CMD="xxxxxxxxxxxxxxxxxx";
BASH_FUNC_make_main_directory_backup%%=() {  local L_CUR_DATE;
BASH_FUNC_ok_to_do_task%%=() {  local -i RET_CODE L_RUN_NO_STOP L_TIMEOUT;
BASH_FUNC_ask_YyYy_timeout%%=() {  local L_REPLY="";
BASH_FUNC_download_http_link%%=() {  local L_ERR_CODE=0;
BASH_FUNC_read_log_on_screen%%=() {  local L_REPLY="";
BASH_FUNC_get_config_param_string_other%%=() {  local FILE_NAME=" ";
BASH_FUNC_copy_link_to_dest%%=() {  local L_NUM_ARG=0;
BASH_FUNC_get_config_param_string_equal%%=() {  local FILE_NAME=" ";
BASH_FUNC_ask_YyRr%%=() {  local L_REPLY="";
BASH_FUNC_ask_YyNn%%=() {  local L_REPLY="";
BASH_FUNC_array_to_file%%=() {  NB_PARAM=$#;
BASH_FUNC_message_success%%=() {  local -a L_ARRAY;
BASH_FUNC_message_header%%=() {  local -a L_ARRAY;
BASH_FUNC_search_after_token%%=() {  local CMD=" ";
BASH_FUNC_message_informal%%=() {  local -a L_ARRAY;
BASH_FUNC_get_my_error_name%%=() {  local __resultvar=$1;
BASH_FUNC_date2stamp_2%%=() {  date --date "$1" +%Y_%m_%d
BASH_FUNC_my_bash_eval_find%%=() {  local L_SOME_CMD="xxxxxxxxxxxxxxxxxx";
BASH_FUNC_trim_quote_in_string%%=() {  sed 's/^"*//;s/"*$//'
BASH_FUNC_stop_or_continue_timeout%%=() {  local L_PARAM1="$1";
BASH_FUNC_move_downloaded_file%%=() {  local L_SRC_FILE=" ";
BASH_FUNC_message_debug%%=() {  local -a L_ARRAY;
BASH_FUNC_date2stamp2%%=() {  date --date "$1" +%Y_%m_%d__%Hh%M
BASH_FUNC_make_bash_local%%=() {  local L_CONF_CUR_VERSION=" ";
BASH_FUNC_get_config_param_string_equal2%%=() {  local FILE_NAME=" ";
BASH_FUNC_file_to_array%%=() {  NB_PARAM=$#;
BASH_FUNC_read_dummy_operator_input_timeout%%=() {  local L_TEMP;
BASH_FUNC_config_at_next_reboot%%=() {  local L_REPLY="";
BASH_FUNC_flag_debug_msg%%=() {  local L_REPLY="" L_FLAG=" ";
BASH_FUNC_array_contains_element%%=() {  local e;
BASH_FUNC_http_link_exists%%=() {  local L_ERR_CODE=0;
BASH_FUNC_print_array_full%%=() {  local -i L_NB_ELEMENT;
BASH_FUNC_read_dummy_operator_input%%=() {  local L_TEMP;
BASH_FUNC_my_bash_eval_rsync%%=() {  local L_SOME_CMD="xxxxxxxxxxxxxxxxxx";
BASH_FUNC_print_asso_array%%=() {  declare -n __p="$1";
BASH_FUNC_return_new_version_file%%=() {  echo;
BASH_FUNC_trim_string2%%=() {  awk '{$1=$1;print}'
BASH_FUNC_deactivate_all_repo%%=() {  local -a L_ARRAY_LIST_CURRENT_REPO;
BASH_FUNC_print_array_if_debug_on%%=() {  local -i L_DEBUG=0;
BASH_FUNC_get_config_param_val_in_section%%=() {  local -i L_DEBUG L_RETURN_CODE=0;
BASH_FUNC_get_string_length%%=() {  local LOCAL_STRING="";
BASH_FUNC_type_a_key_to_continue%%=() {  local L_REPLY;
BASH_FUNC_ask_YyNn_timeout%%=() {  local L_REPLY="";
BASH_FUNC_ask_YyYy%%=() {  local L_REPLY="";
BASH_FUNC_install_new_app_one_by_one%%=() {  local -a L_ARRAY;
BASH_FUNC_create_my_directory_user%%=() {  local l_user_home_flag="$1";
BASH_FUNC_date2stamp_full%%=() {  date --date "$1" +%Y-%m-%d__%H-%M-%S
BASH_FUNC_confirm_twice%%=() {  local -a L_MSG;
BASH_FUNC_message_error%%=() {  local -a L_ARRAY;
BASH_FUNC_get_subpath_front%%=() {  echo "$1" | cut -d"/" -f1-$2
BASH_FUNC_get_config_param_val%%=() {  local FILE_NAME=" ";
BASH_FUNC_mc%%=() {  . /usr/share/mc/mc-wrapper.sh
BASH_FUNC_systemd_unit_full_status%%=() {  local L_COMMON_RETURN_STRING="!";
BASH_FUNC_date2stamp_full2%%=() {  date --date "$1" +%Y-%m-%d__%Hh%Mm%Ss
BASH_FUNC_yes_or_not%%=() {  local L_REPLY="";

They are only exported when explicitly done so.

I tried already above to explain that to you.

… I can only suggest that you study in what cases the profile is used by the shell.

That’s the case.
You don’t read my post.
You just see it

There is no single export command in all the lines of code you dumped on us.

My comment is of course on your statement as quoted immediatly above it.

And yes, as I said in post #4, I did not read/study the mass of code you feel you have to feed to us. I specialy asked you to come with a small consice example of your problem. Nevertheless I tried to understand the kernel of your problem and gave twice the same advice. It is up to you to follow it or not.

And of course, as a last illustration of how confusing your code vs. your statements is, see what @avidjaar said.

Actually I cannot reproduce it (to the extent possible from available description) using moderately recent KDE Live image (20191030). If I export function in /etc/profile.local, this function is available to bash script used as Command in Application tab of “Link to Application” item I created on desktop.

I have found that running the script test from command line, my 78 (seventy height) functions are defined.
Running the same script from the desktop shortcut, only the two first are defined ( the order is system sorting, not from the file sourced ).

Removing the third function give the expected result → 77 functions are defined.

What I did not understand is if there is any syntax error in the offending function why the result is expected from command line and not from shortcut.

Any comment is welcome.

حل مشکلات زناشویی زوج های جوان](https://psychology.avije.org/مشاوره-خانواده/زناشویی/حل-مشکلات-زوج-های-جوان/)

نکات تربیت فرزند پسر و دختر](https://psychology.avije.org/مشاوره-کودک/تربیت/نکات-فرزند-پسر-و-دختر/)

زندگی زناشویی موفق و عاشقانه چگونه است ؟](https://psychology.avije.org/مشاوره-خانواده/زناشویی/زندگی-موفق-و-عاشقانه-چگونه-است/)