问题描述
我试图用执行的命令启动一个新的gnome终端
当我执行gnome-terminal
时,新终端会顺利打开。
现在,当我运行此
gnome-terminal -- "zsh; echo hello"
我希望打开带有zsh的新终端,并打上招呼。
但是我得到的是一个新的终端:
There was an error creating the child process for this terminal
Failed to execute child process “zsh; echo hello” (No such file or directory)
一些重要结果
请看看
❯ 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.
执行以下几行,就像在屏幕上移动一些鬼影一样,但是不会产生可见的输出
❯ gnome-terminal --window -- echo hello
❯ gnome-terminal --tab -- echo hello
❯ gnome-terminal --tab -- echo hello
❯ gnome-terminal --tab --wait -- echo hello
我在哪里犯错?如何完成我的预期工作,即启动一个打有Hello的新zsh终端,并等待下一个命令
解决方法
正在发生的事情是您正在打开一个新终端,但是在实际终端中运行这些命令。如果要在新终端中运行这些命令,则必须指定-x
选项,该选项表示它将在将要打开的终端中执行命令行的其余部分。现在,您可以编写命令,但是您需要为zsh指定-c
选项,以便zsh将第一个参数“逗号内的命令”作为命令。现在终端将执行命令,并保持打开状态,不会闪烁。但是它没有外壳,我想您想继续编写命令,因此您需要exec zsh
。就是这样。
会是这样的:
gnome-terminal -x zsh -c 'echo hello; exec zsh'
,
您的代码的第一行可能包含以下内容:
#!/usr/bin/expect -f
或
#!/bin/bash
确保此目录存在。例如,您可能正在运行该程序,但未安装该程序。