The script basically has output that the user should read. I was thinking of this:
#!/bin/bash
#cd to the script dir if executed from outside
SCRIPT_PATH=$(dirname "$(readlink -f "$0")")
cd "$SCRIPT_PATH"
if [ ! -t 1 ]; then #not from terminal
SCRIPT=$(basename "$(readlink -f "$0")")
x-terminal-emulator --profile "$USER" --working-directory "$SCRIPT_PATH" -e "./$SCRIPT" &
exit 0
fi
echo "output"
#keep terminal open
bash
but this has the problem that if you try to close the window of the new terminal (when executed from nautilus, pgrep says only one bash process) or the 'old' terminal (when executed from a already open terminal, pgrep says two bash processes), that "There is still a process running in this terminal. Closing the terminal will kill it."
I'm looking for a complete solution: can run from a open terminal, can run from nautilus or another file manager, will always allow the user to read output, won't leave processes hanging when exits and won't show that warning on the user innocently closing the window.
I'm pretty sure that the 'process' making the visible console show that warning is the bash
at the last line, but that bash is the only thing allowing the echo to be seen if the script is run from nautilus.
read
command at the end and it will wait for input from user before closing. If you want the output of your script start your script from a terminal do not use nautillus to start it, it would be the best way to do what you want to do.if[ ! -t 1 ]; then SUBPROC=1 x-terminal-emulator ...
and at the endif [ "$SUBPROC" -eq 1 ]; then read
or similar. You'd think this would be a easy and catered for usecase sigh.