Whenever I open a .sh file, it opens it in gedit instead of the terminal. I can't find any option similar to Right Click → Open With → Other Application... → Terminal.
How do I open this file in the terminal?
|
Whenever I open a .sh file, it opens it in gedit instead of the terminal. I can't find any option similar to Right Click → Open With → Other Application... → Terminal. How do I open this file in the terminal? |
||||
|
Go to the directory where the first do
If you seem to be somewhere else, you can use the absolute path
or
or even
these are all ways of describing the same place. Once you've made it to the location of your script, type
If you can see the
Now that we are in the same directory as the script, we have to specify to the shell that we want to execute the file by giving its location
If your script has been written correctly it will run without errors... |
|||||
|
|
There are a few ways to do this. Option 1
Option 2
|
||||
|
|
|
I am a noob in Linux and I just had the same problem. If all else fails:
|
||||
|
|
|
The problem I have found on a few distributions is they have hidden the preferences option in Nautilus, but to fix it in Ubuntu and other distributions using Gnome3 is the same (literally just done the Fedora version of this and posting the actual fix to remind me how in the future).
that will give you the option to edit, view or run the file going forward |
||||
|
|
|
|||||
|
|
In Ubuntu 16.04 this is how to open it in Terminal: Go to the The problem is that it's by default set to |
|||
|
|
|
Well, I too faced the same problem. I wanted to execute the .sh file and it opened with Gedit on CentOS 7. So here is what I did:
|
||||
|
|
|
Give execute permission to your script:
And to run your script:
Since
|
|||||||||||||||||
|
|
On Ubuntu 13.04 executable files opened in Nautilus are now opened in gedit by default rather than prompting the user to execute them. To enable the classic behavior you need to adjust the preferences: Nautilus → Edit menu → Preferences → Behaviour tab → Click the radio button near Ask each time. |
|||||||||||||||||
|
|
You can also use For example:
|
|||||
|
|
2 main steps.
Now, when you double click the file on the desktop, it should execute.
no need for |
||||
|
|
|
Open a terminal and navigate to the folder where the
|
|||||||||
|
|
If you place your shell script or other executable you create in /usr/local/bin it will be found and executed without having to provide a folder path in the command line or adding ./ to the name. For example I created the following simple 3 line bash script to display disk UUIDs:
I called the file uuid and placed it in /usr/local/bin. All I need enter on the command line is:
|
|||
|
|
PrerequisiteBefore you can run the .sh file, you need to make it executable:
WarningMake sure you trust the source where you got the file from. It could be a virus. The very simple way
This has problem. The terminal will close immediately and you will not be able to see the output. The simple way
The way professionals do it
Why do it the complicated way?The terminal has a rich set of powerful tools that are accessible by typing the commands. Professionals locate the .sh file by typing
or you can run and redirect the output to a file:
or you can filter the output for keywords (e.g. "apples") an then redirect to a file:
There are thousands of things you can to to that file just by typing a few commands. Another one, you can download a file from the Internet with one simple command:
And then open the file like this:
|
|||||
|
|
You need to mark shell scripts as executable to run them from the file manager:
|
|||||||||||||
|
ruby foo.rb– glenn jackman Jun 11 '13 at 1:24