我正在定义一个函数,我.bashrc
用它来调用多个其他函数。
function startday {
irene
}
Run Code Online (Sandbox Code Playgroud)
这有效,(irene
是一个定义和来源的函数)但是,我想在另一个终端中执行它。
function startday {
gnome-terminal -c "irene"
}
Run Code Online (Sandbox Code Playgroud)
说 Failed to execute child process "irene" (No such file or directory)
irene
激活一个 virtualenv,所以我希望终端在运行命令后不退出。(不用说,简单地irene
在终端上执行确实能成功执行函数。)
在我的 gnome 终端版本上
$ gnome-terminal --version
GNOME Terminal 3.22.0
Run Code Online (Sandbox Code Playgroud)
我没有选择-c
,但我有选择-x
或-e
但是,如果您想开始运行 .bashrc 中的gnome-terminal
内部函数,您可以尝试这样做:
gnome-terminal -x "bash" -ic "irene"
Run Code Online (Sandbox Code Playgroud)
请注意,bash 的-i
选项将确保您的.bashrc
值被评估,因此irene
函数可用。
另请注意,irene
函数完成操作后将gnome-terminal
停止。您可以考虑在之后 irene
运行一些命令,例如:
gnome-terminal -x "bash" -ic "irene; sleep 2;" # wait 2 seconds after "irene" stops
Run Code Online (Sandbox Code Playgroud)
或者
gnome-terminal -x "bash" -ic "irene; bash;" # run NEW instance of bash after "irene" stops
Run Code Online (Sandbox Code Playgroud)
如果 irene 函数设置了一些环境变量,则只有导出它们,它们才可以在这个新的 bash 实例中访问。
function irene() {
# ...some code
export variable="value of variable"
# ...some code
}
Run Code Online (Sandbox Code Playgroud)
代替
function irene() {
# ...some code
variable="value of variable"
# ...some code
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
586 次 |
最近记录: |