I have this script:
#!/bin/bash
cd "$(cd "$(dirname "$0")" && pwd)"
python3 GWF_CS.py & disown
sleep 5
exit
I have two questions.
- How can I close the terminal window after the py is open?
- How can I change the icon oof the open py?
P.S. exit
doesn't work.
CodePudding user response:
I'm unsure about setting a custom icon on Unix, but to close the terminal without terminating the script, you can use screen.
Start the screen with
screen -S "name_of_screen"
Then run your script
./bash_script.sh
Then disconnect from the terminal by doing CONTROL A then CONTROL D You can now close the terminal window without stopping the script from executing.
For insight on starting a screen from within a bash script, see here.
CodePudding user response:
Script can run as new process and exit
exits script and this process, not current process in terminal (bash) which runs as parent process for your script.
If you put some echo
after exit
then it will never display it - so it shows that exit
works but in different way then you expect.
In bash you can try to run
exec script.sh
and it should replace current process in terminal (bash) with your process (script) and when script will exit then it should close terminal.
In script you can try to get Parent Process ID
and (gracefully) kill it
kill $PPID
You can search more on similar portal Ask Ubuntu
Is there a command to close a terminal window via commandline?
CodePudding user response:
if you want to run a script in the background you can simply create a service see this article
about the icon does your py has a gui if so consider compiling it to an excutable and add an icon to it .
you can do so with pyinstaller :
pyinstaller --windowed -i youricon.icns GWF_CS.py
for more info see pyinstaller docs