Open Terminal with CLI
This guide will show you how to open terminal with CLI when you are scripting in desktop environment.
Problem
You are doing bash scripting, and you want to open terminal with CLI in the script.
Solution
Step 1: Check your terminal emulator
In Ubuntu, the default option is gnome-terminal
; in Raspbian, the default option is lxterminal
. Find out the terminal emulator you are using.
Step 2: Define command to execute after main command
In most cases, you would like the newly opened terminal to stay open after the main command is executed.
- Keep interact with the terminal after the main command is executed:
- Keep the terminal open for a certain amount of time:
- Keep the terminal open forever:
Step 3: Open terminal with CLI
gnome-terminal -t "Terminal Title" --active -- bash -c "echo \"Hello World\"; $terminate_command"
For gnome-terminal
, you can check the function implementation at my GitHub
For lxterminal
, you can check the function implementation at my GitHub
Reference
Error Correction
If you find any mistakes in the document, please create an Issue or a Pull request or leave a message in Discussions or send me a mail directly with the mail icon at the bottom right. Thank you!