Why commands inside bash script lost effectiveness?

Hi,

I have a bash script to run many system commands on CentOS machine, but I am puzzled by some commands had no effect on parent environment.

For example, I want to refresh the desktop xdg menu when some processes added or deleted items from desktop xdg menu. If I run "killall gnome-panel" directly to command line in a terminal, it'll refresh the gnome panel (killed the old panel, and restart the panel again) updated desktop xdg menu. But if I added "killall gnome-panel" to the bash script and run the script in the terminal, nothing did happen, it did not refresh the gnome-panel at all, just like it was not called.

I think that might be sub process could not affect to parent environment, but I could not find a solution to fix it . Any advice would be much appreciated.

BTW, I don't think the "killall gnome-panel" is an appropriate command to be used for refreshing or updating desktop xdg menu, appreciate if anyone know better commands to refresh or update the xdg menu.

Thank you.

Kind regards.

Disclaimer: I don't use GNOME and know nothing of gnome-panel.

At the very least, show us the script, so we can rule out an error there (it may be a simple, single line, but we don't know that at this point).

Are any error messages generated? Did you check the exit status of killall?

Are you running as the same user when running the script as when invoking the command directly?

A child process cannot affect its parent's environment, but I don't think that's relevant; killall simply opens /proc and looks for matching processes.

Regards,
Alister

Are you actually just running these "from a script" or are you running these from some other, separate environment like a crontab or the like? If it's run from a shell not descended from your login, it won't have your login information.

You are right. The script was running from clicking a python wx button, the issue I've just figured out is there is another command needs be run before it as following script.

exec su -l ${user}
killall gnome-panel

The "exec su -l ${user}" refreshed the change of user access permission, but lets user to log into another environment where the following "killall gnome-panel" won't afffect to the current parent environment which called script.

$ update_user_id.sh

In update_user_id.sh:

exec su -l ${user}
killall gnome-panel

The question is really, whether it is possible to make the subsequent login and changes to affect to parent environment? Or there is no way to make it work?

Thank you.

Kind regards.

$ update_user_id.sh

In update_user_id.sh:

exec su -l ${user}
killall gnome-panel

The environment is a list of keys and values mapped into a process' address space. kill (and killall which is a kill wrapper) does not affect it.

If you are using exec in a script, commands which follow will not execute because the exec'd command has replaced the shell.

You probably want to use su(1)'s -c option. I say "probably" because it's not clear to me what you're doing and under what circumstances you're doing it.

Regards,
Alister