im-launch in Ubuntu startup

44,163

Solution 1

-e check the file /usr/bin/ibus-daemon exists or not? exist means true does not exist means false.

! wants to confirm above value is false if above value is true, it will not execute anything.

[ "x$XDG_SESSION_TYPE" = "xwayland" ] this can have either one of below values based on how you choose to login at the login screen. which session you will choose x11 or wayland.

"xx11" = "xwayland" "xwayland" = "xwayland"

example output of $XDG_SESSION_TYPE

administrator@pratap:~$ echo $XDG_SESSION_TYPE
x11

another example:

administrator@pratap:~$ echo $XDG_SESSION_TYPE
wayland
administrator@pratap:~$ 

if the first expression is false and x$XDG_SESSION_TYPE = xwayland then exec the command env IM_CONFIG_CHECK_ENV=1 im-launch true

if the first expression is true or x$XDG_SESSION_TYPE is not equal to xwayland then don't do anything.

see man test

! EXPRESSION
              EXPRESSION is false

and

   -e FILE
          FILE exists

you can read more about what this command does then exec env IM_CONFIG_CHECK_ENV=1 im-launch true;

see man env & man im-launch


By default in Ubuntu 19.10 /usr/bin/ibus-daemon exists. so the command will not be executed.

env IM_CONFIG_CHECK_ENV=1 im-launch true

when there is the file /usr/bin/ibus-daemon and my session is x11

here is something about IM

enter image description here

when there is no file /usr/bin/ibus-daemon and my session is wayland

here is the thing which is different from above, which means the env is applied and then a chain reaction followed.

enter image description here

so, if you disable or enable this from startup list nothing happens unless no existence of this file /usr/bin/ibus-daemon and your session is wayland conditions are met.

Solution 2

I was doing some research on how to configure Ubuntu to make it more performant and ended up here, which is interesting.

My im-launch startup entry:

sh -c 'if [ "x$XDG_SESSION_TYPE" = "xwayland" ] ; then exec env IM_CONFIG_CHECK_ENV=1 im-launch true; fi'

As answer was detailed by @UnKNOWn but @foobar's comment was my situation, so I took a deep dive.

Breaking The Command Down:

sh is a command language interpreter that executes commands read from a command line string, the standard input, or a specified file.

exec command in Linux is used to execute a command from the bash itself.

if CONDITION true THEN execute COMMAND

im-launch command is used to start a input method framework server daemon such a ibus-daemon, set up the appropriate environment variables for the client programs,and execute SESSION-PROGRAM such as x-session-manager.

ibus-daemon is a daemon program for ibus and it is also a start up program for users to activate ibus daemon, engines and panel.

daemon is a computer program that runs as a background process, rather than being under the direct control of an interactive user.

ibus is an intelligent input bus.

bus is simply a set of wires connecting multiple modules (processor, memory, IO devices).

The exec

Then my question was why do exec env when we are already execution the command from sh.

The exec command replaces the current shell process with the specified command. Normally, when you run a command a new process is spawned (forked), the exec command does not spawn a new process. Instead, the current process is overlaid with the new command. In other words the exec command is executed in place of the current shell without creating a new process.

Use of env - If you want to modify the environment for a program before executing the main program, you'd often write an script and at the end of it start the main program. But there is no need for the script to stay in memory at that time. So, exec is used in these cases so that, the main program can replace the mother script.

Share:
44,163
Afsal
Author by

Afsal

An Opensuse Tumbleweedian who entered in to the linux world through Ubuntu :) xD :}

Updated on September 18, 2022

Comments

  • Afsal
    Afsal over 1 year

    I found this im-launch startup entry after installing Ubuntu 19.10 which executes sh -c 'if ! [ -e "/usr/bin/ibus-daemon" ] && [ "x$XDG_SESSION_TYPE" = "xwayland" ] ; then exec env IM_CONFIG_CHECK_ENV=1 im-launch true; fi'

    I want to know the purpose of this entry and what would happend if i disabled it ?

  • Afsal
    Afsal over 4 years
    Thank you . I appreciate your detailed answer for my doubt . People like you makes askubuntu.com awesome .
  • foobar
    foobar about 4 years
    Well, I can underdstand the syntax of the command - but in simple words: what does it do in the end? What is im-launch?
  • foobar
    foobar about 4 years
    I know how to use manpages... But man im-launch does not enlighten me. It seems very low level. Why does Ubuntu put this into my user-space start programs?
  • UnKNOWn
    UnKNOWn about 4 years
    its kind of thing related to multi languages, keyboard layouts.. specially some kind of chinees, japanees.. etc.
  • Sam Bull
    Sam Bull over 3 years
    What I'm most confused about is the true. It appears to execute the program passed to it, so in this case it just executes true, which doesn't actually do anything. I'm trying to figure out why fcitx doesn't get started, because this startup script doesn't seem to do anything at all. It seems like it should instead run something like im-launch $GTK_IM_MODULE, in order to actually start the correct IM method.
  • Yannis Dran
    Yannis Dran over 3 years
    I agree with foobar. I left being puzzled, I had to spend 25 minutes of reading the comment again and again till I get the aha! moment. It is a good, detailed answer, but not a beginner-wise. Thanks anyway for the effort.
  • David
    David over 2 years
    This is a comment not an answer, you should have posted this as such.
  • karel
    karel over 2 years
    It looks like a valid answer to me.