Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Basically I want to make a file that when I open it normally, it opens a new terminal and runs a set command that I preset into it.

Here's an example:

I open a file with gedit, I type in, Sensors, save it, close the file and then open it normally. When it opens, it automatically makes a new terminal and runs the command Sensors.

I have been trying to find this for a while and I haven't been able to find much at all.

I've tried making it a .sh file and I've added #!/bin/bash and #!/bin/sh, but neither of them seemed to work.

share|improve this question
1  
Did you mean something like this askubuntu.com/questions/38661/how-do-i-run-sh-files-in-terminal ? –  TuKsn May 14 at 22:44
    
How would you "open it normally"? Do you mean double clicking the file and having it run in a newly opened terminal? Or do you mean executing it from one terminal and have it open a new one and run your script there? Oh, and the command is sensors, not Sensors. –  terdon May 16 at 1:52

2 Answers 2

To run a command in a terminal (for example, top) you can do:

gnome-terminal -e top

So you can put this in a file, call it for example mytop, with content:

#!/bin/bash
gnome-terminal -e top &

Then you make the file executable (with the file manager, or with the command chmod +x mytop) and when you double click on it, a terminal with top running in it is open.

Caveat: if you exit top, the terminal will exit too. If you want a shell after the command exit, a little trick is needed:

gnome-terminal -e "bash -c 'top; exec bash'" & 

Be careful with the quotes --- you can substitute "top" for the command you want and you're set.

share|improve this answer

open a new document and type the terminal command whatever you want like sensors or firefox and save the document.

now right click it properties and goto permissions and select allow executing file as a program.

now if u double click that file it will ask u how to run the file you can simply run or you can run in terminal.

if double click dont ask the file how to run then goto nautilus menu bar - edit/preferences in that goto behaviour and select ask every time under executable text files.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.