gpt4 book ai didi

linux - 在 Ubuntu 上使用 gnome-terminal --tab 选项打开选项卡并运行脚本

转载 作者:太空宇宙 更新时间:2023-11-04 04:04:58 26 4
gpt4 key购买 nike

我当前位于我的项目目录中。

$ pwd

/home/karthik/Projects

我从命令行执行以下操作。

gnome-terminal --tab --working-directory="/home/karthik/mininet" -e  "sudo ./my_topo.sh"

我希望上面的命令执行以下操作

1) open a tab 
2) go to working directory `/home/karthik/mininet`
3) execute the script `my_topo.sh`

相反,它似乎执行以下操作。

1) open a terminal. 
2) go to working directory `/home/karthik/mininet`
3) execute the script `my_topo.sh`

另外,在相关说明中,如何打开具有 sudo 权限的选项卡,以便不必输入密码?

我尝试执行以下操作

WID= xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}'; xdotool windowfocus $WID; xdotool key ctrl+shift+t $WID

这确实会打开一个新选项卡,但如何在新选项卡而不是旧选项卡中执行以下命令。

cd /home/karthik/mininet;
sudo ./my_topo.sh

最佳答案

在您的 bash 脚本中尝试一下:

   #!/bin/sh

gnome-terminal -x sudo ./home/karthik/mininet/my_topo.sh

关于linux - 在 Ubuntu 上使用 gnome-terminal --tab 选项打开选项卡并运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21591757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com