Question

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). 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:

  • Open terminal
  • navigate "cd /var/www/myproject"
  • run "compass watch"

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. My question is, can this be done with one single (simple) file that is launched from the desktop?

Was it helpful?

Solution

Either you make a shell script (.sh file, don't forget to make it executable) or you make a desktop file (.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).

myscript.desktop:

[Desktop Entry]
Exec=bash -c 'cd /var/www/myproject && compass watch'
Name=myscript
Terminal=true
Type=Application

(Note the Terminal=true part.)

myscript.sh:

#!/bin/sh
gnome-terminal -e 'cd /var/www/myproject && compass watch'

(Assuming you want to use GNOME Terminal.)

Of course, there are numerous other options.

OTHER TIPS

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:

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 (:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top