Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
2 of 5 added 1205 characters in body

Instead of hard-coding gnome-terminal, konsole, et cetera, use the Alternatives system. The program that executes the default terminal emulator is:


On my system, it opens a new instance of Konsole every time I execute this command.

All terminal emulator seems to have different options, the only reliable way to get the terminal stay open is by using a wrapper for the script.

# Usage: name-of-this-file program arg1 arg2 argN
if [ -n "$1" ]; then
    # if there are arguments, put the contents in a file since arguments with spaces could be messed up
    if [ $# -gt 1 ]; then
        export IAMTEMPFILE=1
        export EXECUTEMEPLOX=$(mktemp)
        echo "$@" > "$EXECUTEMEPLOX"
        unset IAMTEMPFILE
        export EXECUTEMEPLOX="$1"
    x-terminal-emulator -e "$0"
    if [ -n "$EXECUTEMEPLOX" ]; then
        if [ -n "$IAMTEMPFILE" ]; then
            unset IAMTEMPFILE
            # note: make sure the executed program does not change $EXECUTEMEPLOX
            . "$EXECUTEMEPLOX"
            # and remove the file with the command
            rm -f "$EXECUTEMEPLOX"
            # no temp file, just execute the command
    # and replace the current shell with bash
    exec bash