Say I need to write a script that will launch a terminal and execute a command and I need that to work on various systems. How can I do that in a safe and portable manner?
Is xterm always installed? I assume that any *nix with a GUI must have some terminal emulator. How can I get to it? Debian systems have x-terminal-emulator but that, apparently, does not even work in Red Hat, let alone non-Linux *nixes.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I don’t think you can. xterm need not be installed everywhere, and indeed probably isn’t by default. Especially when a desktop environment is in use that provides its own terminal.
I think your best bet is probably to check for the existence of a few different terminals (say, xdg-terminal, x-terminal-emulator, gnome-terminal, konsole, xterm). And maybe work towards getting xdg-terminal actually added to the FreeDesktop.org standards.
Then you’ll get to find that different terminals have different ways to run commands, and sometimes even different versions of the same terminal… e.g., see Debian Bug #648271.
You should probably also give the admin/user a way to set a custom command. It’ll surely be needed.
Method 2
Yeah you need to use a wrapper. There is a good one included with i3 WM. Explained here: http://build.i3wm.org/docs/i3-sensible-terminal.html
Just copy this into a shell function in your script:
http://code.stapelberg.de/git/i3/tree/i3-sensible-terminal
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0