I am trying to launch a new gnome-terminal with a command executed
When I execute gnome-terminal
, a new terminal opens smoothly.
Now when I run this
gnome-terminal -- "zsh; echo hello"
I expect a new terminal with zsh to open, with hello printed.
But what I get is a new terminal with this:
There was an error creating the child process for this terminal
Failed to execute child process “zsh; echo hello” (No such file or directory)
Some important results
Please take a look
❯ gnome-terminal -e "echo hello"
# Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.
❯ gnome-terminal --command "echo hello"
# Option “--command” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.
Executing the following lines, does something like some ghost moves on the screen, but produces no visible output
❯ gnome-terminal --window -- echo hello
❯ gnome-terminal --tab -- echo hello
❯ gnome-terminal --tab -- echo hello
❯ gnome-terminal --tab --wait -- echo hello
Where am I making mistake ? How can do do my intended job ie launch a new zsh terminal with hello printed, and waiting for next command
What it's happening is that you are opening a new terminal, but running those commands in your actual terminal. If you want to run those commands IN the new terminal, you've got to specify the -x
option, which says that it will execute the remainder of the command line inside the terminal that will be opened. Now, you can write the command, but you need to specify the -c
option for the zsh, in order for zsh to take the first argument "The commands within commas" as a command. Now the terminal will execute the command, and will stay opened, it won't do that blinking. But it won't have a shell, and I guess you want to keep writing commands, so you will need to exec zsh
. And that's it.
It would be something like this:
gnome-terminal -- zsh -c 'echo hello; exec zsh'