How to run CLI scripts inside a GUI environment
When you want to run a script just with a double-click on the script file, these are the steps you need to follow.
- You can create two executables: one to “launch” the script with a terminal emulator and other with the script itself. You can also execute the script directly if your file manager has that option (in KDE’s Dolphin you can right-click on the script file and select “Actions -> Execute with Konsole” to run the script with the terminal emulator, without needing a launcher file).
- Inside the “launcher” file, type a command to open your desired terminal emulator with the script file. For example, to open Konsole (KDE Terminal):
#!/bin/bash konsole -e ~/my_command.sh
- Inside the script file, add your script. If you want the terminal window to close automatically when the script finishes its work, add
kill -9 $PPIDat the end. Sometimes the terminal will close even without the previous command. In those cases, to keep the window open, append
$SHELLto the end of the script.
- Finally, make both files executable.
#!/bin/bash read -p "Continue?: (y/n) " res if [ $res == "y" ] then echo $y done kill -9 $PPID
If you have any suggestion, feel free to contact me via social media or email.
Latest tutorials and articles: