【发布时间】:2017-09-01 00:13:37
【问题描述】:
我想做以下事情:
- 打开一个终端。
- 切换到目标脚本所在的目录。
- 打开为目标脚本提供输入的文本文件。保持/等待,直到用户保存并关闭文本文件。
- 执行目标脚本。
我编写了以下脚本来执行上述操作:
#!/bin/bash
echo "hello"
gnome-terminal -x bash -c "cd ~/automation/DVF99_Automation/Scripts;pwd;gedit sample.txt;python test.py;exec $SHELL"
echo "good bye"
上面给了我以下输出:
user4@user-pc-4:~/Desktop$ ./DAT_run.sh
hello
good bye
在打开的新 gnome 终端上,我看到以下消息:
/home/user4/Scripts
From python script
From python script
From python script
From python script
From python script
以上意味着它已经执行了python代码并且我的要求1,2和4已经满足(不是第3个)。我无法将gedit 窗口作为前台进程,直到它被保存并关闭(因此只有在我关闭在gedit 中打开的文件后才会执行下一条语句)。
这里可能出了什么问题?我是 shell 脚本的新手,我觉得我很可能在这里遗漏了一些东西。我怎样才能达到上述所有要求?
【问题讨论】:
-
会不会是正在执行的
gedit是一个后台启动gedit的shell脚本? -
不。
sample.txt只是一个纯文本文件。 -
我没有提到
sample.txt。我参考了gedit。您可以在调用 gedit 之前添加两个命令type gedit; file $(type -p gedit)。
标签: linux bash shell scripting gnome-terminal