[英]Ubuntu desktop script to open terminal, navigate to a folder and run compass watch
I have tried to search for a simple answer for running a simple script (myscript.sh) from the Ubuntu (13) desktop that would open the terminal, navigate to a folder (/var/www/myproject) and then run the "compass watch" command (and then stay open). 我试图从Ubuntu(13)桌面运行一个简单的脚本(myscript.sh)来搜索一个简单的答案,该脚本将打开终端,导航到一个文件夹(/ var / www / myproject),然后运行“指南针”观看“命令(然后保持打开状态)。 First I thought this would be very simple to accomplish, but after several fails and searches, this particular task/script seems overwhelmingly hard to get to work.
首先,我认为这将很容易实现,但在几次失败和搜索之后,这个特定的任务/脚本似乎非常难以开始工作。
To do this manually is not a big task: 手动执行此操作不是一项大任务:
I thought this would be a walk in the park (although I am quite new to terminal and scripting), but through the searches I got some weird desktop launcher answers and complicated bash scripting functions solutions for sub-shell work-a-rounds. 我认为这将是在公园散步(虽然我对终端和脚本很新),但通过搜索,我得到了一些奇怪的桌面启动器答案和复杂的bash脚本函数解决方案,用于子shell工作。 My question is, can this be done with one single (simple) file that is launched from the desktop?
我的问题是,这可以通过从桌面启动的一个(简单)文件来完成吗?
Either you make a shell script ( .sh
file, don't forget to make it executable) or you make a desktop file ( .desktop
). 您可以创建一个shell脚本(
.sh
文件,不要忘记使其可执行),也可以创建一个桌面文件( .desktop
)。 Either of those can be double-clicked, although the former might bring up a dialog asking whether you want to execute it (can be configured, but only per user, IIRC). 其中任何一个都可以双击,虽然前者可能会显示一个对话框,询问您是否要执行它(可以配置,但仅限每个用户,IIRC)。
myscript.desktop
: myscript.desktop
:
[Desktop Entry]
Exec=bash -c 'cd /var/www/myproject && compass watch'
Name=myscript
Terminal=true
Type=Application
(Note the Terminal=true
part.) (注意
Terminal=true
部分。)
myscript.sh
: myscript.sh
:
#!/bin/sh
gnome-terminal -e 'cd /var/www/myproject && compass watch'
(Assuming you want to use GNOME Terminal.) (假设您想使用GNOME终端。)
Of course, there are numerous other options. 当然,还有很多其他选择。
I didn't get well where is your problem ... If you want to run a script like that (double clic) you should first make it executable: 我不顺利你的问题在哪里...如果你想运行这样的脚本(双clic)你应该首先让它可执行:
chmod u+x myscript.sh
Then you just have to place a link to this script on your desktop (or the script itself if you want ...) When double-clicking it, you will have the possibility to run it in a terminal. 然后你只需要在你的桌面上放置一个这个脚本的链接(或者你想要的脚本本身......)当双击它时,你可以在终端中运行它。
Then put whatever you want in your script ( the navigate "cd /var/www/myproject" , run "compass watch" part) and end the script (myScript.sh) file with $SHELL
to keep the terminal open after the script execution (: 然后在你的脚本中放入你想要的任何东西( 导航“cd / var / www / myproject”,运行“指南针监视”部分)并用
$SHELL
结束脚本(myScript.sh)文件,以便在脚本执行后保持终端打开(:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.