How to merge two bash calls into one in linux

127 Views Asked by At

I have 2 linux gnome commands that I would like to merge into one.

One is giving me the title:

gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\)[`gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\).findIndex\(a\=\>a.meta_window.has_focus\(\)===true\) | cut -d"'" -f 2`].get_meta_window\(\).get_title\(\) | cut -d'"' -f 2

While the other one is giving me the program name:

gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\)[`gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\).findIndex\(a\=\>a.meta_window.has_focus\(\)===true\) | cut -d"'" -f 2`].get_meta_window\(\).get_wm_class\(\) | cut -d'"' -f 2

Now the calls are almost the same yet I fail to retrieve both arguments at once. How can I use both get_meta_window and get_title in one call?

1

There are 1 best solutions below

1
Omniver On

In bash you can combine two commands using { list; } where list is a list of commands.

Example:

{ echo foo; echo bar; }
foo
bar

You can then filter your concatenated output any way you’d like:

Example 2: (change the newlines to asterisks)

{ echo foo; echo bar ; } | tr “\n” “*“
foo*bar*

Note: spacing is very important. There is a space after the opening { and before the closing }.