I'm executing a bash script through a custom created service. At user login, the script is executed. I can verify that the program is running with the ps -ef command.

The only thing I want to have happen is, I want the Terminal to open and display the output of the script execution.

I am new to Linux. Still getting to know things. Not a very good experience so far.

Running Ubuntu 18.04.

  • 2
    This aught to work gnome-terminal -x bash -c "command" Aug 8, 2018 at 14:12
  • Where exactly do I put this? in the .sh file? The script runs an executable. The script looks like this: code#!/bin/sh export GPU_MAX_ALLOC_PERCENT=100 ./ethdcrminer64code
    – GaaTY
    Aug 8, 2018 at 14:17
  • Yes in the bash file Aug 8, 2018 at 14:17
  • Not working for me. I changed it to: `code'#!/bin/sh export GPU_MAX_ALLOC_PERCENT=100 gnome-terminal -x bash -c "./ethdcrminer64" Now it does't execute at all. P.S. I can't seem to get the code mini-markdown right -_-
    – GaaTY
    Aug 8, 2018 at 14:31
  • How did you create the user service ? Via .desktop file /startup applications menu, or systemd service ? Aug 8, 2018 at 15:57

2 Answers 2


Let me use this simple example to demonstrate one way of having that done:

  1. Two scripts:

    • launcher.sh, and
    • sample.sh
  2. Content of scripts:

    • launcher.sh:

      #!/usr/bin/env bash
      gnome-terminal --working-directory="/home/georgek/Documents/askubuntu" -- '--rcfile ./setup.bash ./launcher.sh'
    • sample.sh:

      #!/usr/bin/env bash
      du -h ./; read line;
  3. Call sample.sh from launcher.sh like this: launcher.sh and that will pass the file sample.sh to the terminal, note: the read line prevents gnome-terminal from closig till you press the ENTER key. Modify as it as you like.

NOTE: - -- is preferred to -x as reported by bash - --working-directory="/home/georgek/Documents/askubuntu" tells terminal to run command from this directory.

  • Use this file to set variables, from man bash:

    --rcfile file Execute commands from file instead of the system wide initialization file /etc/bash.bashrc and the standard personal initialization file ~/.bashrc if the shell is interactive (see INVOCATION below).

  • I am not getting this right. I got sample.sh to run from launcher.sh, but when I tried on my own script, terminal opens but nothing happens in terminal.
    – GaaTY
    Aug 10, 2018 at 7:45

Best approach would be to install screen or byobu for nicer UI, and run your script there:

screen -S sessionname -d -m /path/to/script

This will let you reattach to session with

screen -r sessionname

Considering the fact that you're starting it from systemd service, you may need to have two things done: either allow multiuser session for everyone or configure individual access only for your username. This will need to have custom config file and pass that to screen with -c flag.

See also:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.