How do I run .sh files?
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?
command-line bash
|
show 1 more comment
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?
command-line bash
Does that script aim to set up env variables for further use?
– Rob
May 1 '11 at 10:47
1
You shouldn't use extensions on scripts. At some point in the future, you may find that a different language is more suitable to do the task your current script is doing. And then you have a problem. Do you keep the old name, with a completely misleading extension, or do you rename it, possibly having to edit alot of places where your script is used?
– geirha
May 1 '11 at 14:07
You don't need the file extension. It's nice to have but is not needed. The OS doesn't look at the file extension. It looks at the data
– ActionParsnip
May 4 '11 at 17:41
5
Meh, if you rewrite foo.sh in ruby, you can always use the .sh file to launchruby foo.rb
– glenn jackman
Jun 11 '13 at 1:24
In Dolphin you can press F4 and a console opens
– Motte001
Jun 16 '16 at 16:47
|
show 1 more comment
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?
command-line bash
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?
command-line bash
command-line bash
edited Feb 11 '16 at 20:44
Jorge Castro
36.1k105422617
36.1k105422617
asked May 1 '11 at 2:39
AlexAlex
1,4263103
1,4263103
Does that script aim to set up env variables for further use?
– Rob
May 1 '11 at 10:47
1
You shouldn't use extensions on scripts. At some point in the future, you may find that a different language is more suitable to do the task your current script is doing. And then you have a problem. Do you keep the old name, with a completely misleading extension, or do you rename it, possibly having to edit alot of places where your script is used?
– geirha
May 1 '11 at 14:07
You don't need the file extension. It's nice to have but is not needed. The OS doesn't look at the file extension. It looks at the data
– ActionParsnip
May 4 '11 at 17:41
5
Meh, if you rewrite foo.sh in ruby, you can always use the .sh file to launchruby foo.rb
– glenn jackman
Jun 11 '13 at 1:24
In Dolphin you can press F4 and a console opens
– Motte001
Jun 16 '16 at 16:47
|
show 1 more comment
Does that script aim to set up env variables for further use?
– Rob
May 1 '11 at 10:47
1
You shouldn't use extensions on scripts. At some point in the future, you may find that a different language is more suitable to do the task your current script is doing. And then you have a problem. Do you keep the old name, with a completely misleading extension, or do you rename it, possibly having to edit alot of places where your script is used?
– geirha
May 1 '11 at 14:07
You don't need the file extension. It's nice to have but is not needed. The OS doesn't look at the file extension. It looks at the data
– ActionParsnip
May 4 '11 at 17:41
5
Meh, if you rewrite foo.sh in ruby, you can always use the .sh file to launchruby foo.rb
– glenn jackman
Jun 11 '13 at 1:24
In Dolphin you can press F4 and a console opens
– Motte001
Jun 16 '16 at 16:47
Does that script aim to set up env variables for further use?
– Rob
May 1 '11 at 10:47
Does that script aim to set up env variables for further use?
– Rob
May 1 '11 at 10:47
1
1
You shouldn't use extensions on scripts. At some point in the future, you may find that a different language is more suitable to do the task your current script is doing. And then you have a problem. Do you keep the old name, with a completely misleading extension, or do you rename it, possibly having to edit alot of places where your script is used?
– geirha
May 1 '11 at 14:07
You shouldn't use extensions on scripts. At some point in the future, you may find that a different language is more suitable to do the task your current script is doing. And then you have a problem. Do you keep the old name, with a completely misleading extension, or do you rename it, possibly having to edit alot of places where your script is used?
– geirha
May 1 '11 at 14:07
You don't need the file extension. It's nice to have but is not needed. The OS doesn't look at the file extension. It looks at the data
– ActionParsnip
May 4 '11 at 17:41
You don't need the file extension. It's nice to have but is not needed. The OS doesn't look at the file extension. It looks at the data
– ActionParsnip
May 4 '11 at 17:41
5
5
Meh, if you rewrite foo.sh in ruby, you can always use the .sh file to launch
ruby foo.rb
– glenn jackman
Jun 11 '13 at 1:24
Meh, if you rewrite foo.sh in ruby, you can always use the .sh file to launch
ruby foo.rb
– glenn jackman
Jun 11 '13 at 1:24
In Dolphin you can press F4 and a console opens
– Motte001
Jun 16 '16 at 16:47
In Dolphin you can press F4 and a console opens
– Motte001
Jun 16 '16 at 16:47
|
show 1 more comment
16 Answers
16
active
oldest
votes
Give execute permission to your script:
chmod +x /path/to/yourscript.sh
And to run your script:
/path/to/yourscript.sh
Since .
refers to the current directory: if yourscript.sh
is in the current directory, you can simplify this to:
./yourscript.sh
13
+1 only answer to show adding execute permissions in a terminal only way.
– Hailwood
May 1 '11 at 3:24
69
If you dobash /path/to/yourscript.sh
then you don't needchmod +x
– Aleksandr Levchuk
May 1 '11 at 4:51
3
Actually, you can use. /path/to/yourscript.sh
if the script have to set up some environment variables.
– Rob
May 1 '11 at 10:46
1
Nobody mentions the traditional:./path/to/yourscript.sh
(without the space after.
)? I find that one is the simplest and easiest to use... But anyways, here is my alternative that should do almost the same as./
would, though I don't see why you wouldn't use./
:(FILENAME=~/rem4space.sh;SLL=$(cat $FILENAME|head -1|sed 's:^#!(.*):1:g');[ ! -z $SLL ] && exec $SLL $FILENAME;sh $FILENAME)
... editFILENAME
to your liking. Also note thatsh
will be used if there is no alternative.
– MiJyn
Jun 19 '13 at 3:50
add a comment |
You need to mark shell scripts as executable to run them from the file manager:
Right click on your
.sh
file and select Properties:
In the Permissions tab, check Allow executing file as program:
Close the Properties window and double-click the file. A dialog will pop up giving you the option to run the script in a terminal:
8
This isn't working in Ubuntu 13.04. Keeps opening in gedit anyway, never asks me to execute. Edit: Nvm, imjustmatthew answers this.
– mpen
Jul 12 '13 at 16:27
Before using this we need to make the file permission for execute using chmod. chmod +x filename.sh or chmod 755 filename.sh
– Arvind Rawat
Mar 16 '17 at 15:11
I don't have popup! IDE is opened straight away, not a popup
– Green
Apr 4 '18 at 10:56
How come I can't find "run in terminal" anywhere on my interface? (Ubuntu 18.04)
– Daniel Möller
May 9 '18 at 22:08
1
@DanielMöller, here is the answer to your question. askubuntu.com/questions/38661/how-do-i-run-sh-files/…
– Akhilesh Dhar Dubey
Aug 16 '18 at 10:19
|
show 1 more comment
Prerequisite
Before you can run the .sh file, you need to make it executable:
- Right-click on the file
- Select Properties
- Select Permissions
- Select Allow executing file as a program
Warning
Make sure you trust the source where you got the file from. It could be a virus.
The very simple way
- Double-click on the file
- Click run in terminal
This has problem. The terminal will close immediately and you will not be able to see the output.
The simple way
- Open Applications -> Accessories -> Terminal
- Drag and drop the .sh file into the terminal and press Enter
The way professionals do it
- Open Applications -> Accessories -> Terminal
Find where the .sh file
- Use the
ls
andcd
commands
ls
will list the files and folders in the current folder. Give it a try: type "ls" and press Enter.- Once you see the folder that you want to go in to, run
cd
, followed by a space, followed by a folder name - If you when into a folder that you did not want, run
cd ..
to go one level up
- Use the
Run the .sh file
Once you can see for example
script1.sh
withls
run this:
./script.sh
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 ls
and cd
. Once you are in the correct current folder you can run the script like this:
./script1.sh
or you can run and redirect the output to a file:
./script1.sh > out.txt
or you can filter the output for keywords (e.g. "apples") an then redirect to a file:
./script1.sh | grep apples > ./only-apples
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:
wget www.google.com/images/logos/ps_logo2.png
And then open the file like this:
shotwell ps_logo2.png
5
Im not sure that The way professionals do it is correct, it's more a case of the simple way the advanced(for for control of output) way
– Hailwood
May 1 '11 at 4:24
add a comment |
Open a terminal and navigate to the folder where the .sh
file is located. Then type:
sh <name of file>.sh
add a comment |
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.
The person who asked the question is talking about Ubuntu 10.10
– edwin
Jun 11 '13 at 0:48
1
Thank you!!! I don't know why they'd change this, couldn't figure out how to execute anything.
– mpen
Jul 12 '13 at 16:28
1
This is the right answer for latest ubuntus.
– gaRex
Apr 11 '15 at 11:44
How do you get to Nautilus in 15.10?
– Yaakov Ainspan
May 23 '16 at 17:54
As of Ubuntu 18.04, you can access the preferences by opening a directory and then clicking "Files -> Preferences" in the top bar.
– tparker
Nov 17 '18 at 20:04
add a comment |
Go to the directory where the .sh
file is by using cd
. In this example I have stored my sh
file as ~/Desktop/shell_practice/test.sh
first do pwd
to figure out where you are, and if it returns /home/username
(where username
is your real username), you can run
cd Desktop/shell/practice
If you seem to be somewhere else, you can use the absolute path
cd ~/Desktop/shell/practice
or
cd $HOME/Desktop/shell/practice
or even
cd /home/$USER/Desktop/shell/practice
these are all ways of describing the same place. Once you've made it to the location of your script, type
ls
If you can see the sh
file in the output, you can use chmod
to make it executable. In my case, remember, the filename is test.sh
, so I would run
chmod u+x test.sh
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 ./
(the current directory followed by a path separator, to distinguish it from the filename). To run my file I would type:
./test.sh
If your script has been written correctly it will run without errors...
Here's a live example:
This worked for me to install Netbeans on ubuntu
– RuD3B0y
Jan 6 '18 at 20:16
Wb, @RuD3B0y, i tried to keep the answers best for noobs, no high tech content, if you have some edits you are welcome.
– TheExorcist
Apr 2 '18 at 17:58
add a comment |
2 main steps.
in terminal, use gedit to write and save script with ".sh" extension to desktop.
(but any text editor can be used)
open Nautilus and right click the script.sh file.
under properties, check box "allow executing file.."
in Nautilus menu, click file,then preferences,then behaviour
check the "run executable text files when they are opened".
Now, when you double click the file on the desktop, it should execute.
no need for .
or ./
add a comment |
In Ubuntu 16.04 this is how to open it in Terminal:
Go to the File Manager > Edit > Preferences > Behavior
for Executable Text Files
and select Ask each time
.
The problem is that it's by default set to View Executable Files when they are opened
.
add a comment |
Right-click the
.sh
file and make it executable.Open a terminal (Ctrl+Alt+T).
Drag the
.sh
file into the terminal window and watch in awe.
1
Welcome to Ask Ubuntu! I recommend to edit this answer to expand it with specific details about how to do the first step. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on AskUbuntu.)
– David Foerster
Jun 10 '17 at 15:49
add a comment |
There are a few ways to do this.
Option 1
In the terminal, access the directory the Bash file is in using
cd
(change directory).
Ex.
cd Downloads
Run
bash <filename>.sh
This also works with .run files. There is an example of this usage at this webpage on updating Rhythmbox.
Option 2
In the terminal, navigate to the directory the bash file is in.
Run
chmod +x <filename>.sh
In Nautilus, open the file.
add a comment |
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:
#!/bin/bash
echo "* UUIDs must match in /etc/fstab and /boot/grub/menu.lst"
sudo blkid
I called the file uuid and placed it in /usr/local/bin. All I need enter on the command line is:
uuid
add a comment |
For Ubuntu 18.04, There is a little modification, as you don't get a pop-up dialog.
So what you need to do is:
Right click on Files, Select Preferences > Select Behavior Tab > Mark 'Ask what to do' option under Executable text file.
Now, When you double-click on any .sh file, you will get a popup, there you can select "run in terminal" option to run your .sh file.
add a comment |
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:
- I navigated to the path of the
.sh
file I wanted to execute. - I opened the terminal.
- And I simply dragged and dropped the on the terminal window and it automatically took that file along with the path as input.
- Hit Enter and you are good to go!
add a comment |
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).
Install
dconf-editor
sudo apt-get install dconf-editor
Run
dconf-editor
using the user account you want this on, i.e NOT root
dconf-editor
Navigate to the following schema:
org.gnome.nautilus.preferences
Change the default option to not open by default:
Find
executable-text-activation
click the worddisplay
and change toask
that will give you the option to edit, view or run the file going forward
add a comment |
I am a noob in Linux and I just had the same problem. If all else fails:
- Open terminal
- Open the folder containing the .sh file
- Drag and drop the file into the terminal window
- The file's path appears in terminal. Press Enter.
- Voila, your .sh file is run.
add a comment |
You can also use .
tricks, with the suggestion of other answers.
For example:
chmod +x filename.sh
, assuming you have already gone to the path to file then run the file with any one of these command:
sh filename.sh
./filename.sh
. filename.sh
2
warning: These three commands are not equivalent. If your shebang references a different binary (like Stack), then the third command will try parsing arguments with Bash, which will fail.
– Jezen Thomas
Feb 18 '17 at 11:12
add a comment |
protected by Community♦ Aug 21 '18 at 12:25
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
16 Answers
16
active
oldest
votes
16 Answers
16
active
oldest
votes
active
oldest
votes
active
oldest
votes
Give execute permission to your script:
chmod +x /path/to/yourscript.sh
And to run your script:
/path/to/yourscript.sh
Since .
refers to the current directory: if yourscript.sh
is in the current directory, you can simplify this to:
./yourscript.sh
13
+1 only answer to show adding execute permissions in a terminal only way.
– Hailwood
May 1 '11 at 3:24
69
If you dobash /path/to/yourscript.sh
then you don't needchmod +x
– Aleksandr Levchuk
May 1 '11 at 4:51
3
Actually, you can use. /path/to/yourscript.sh
if the script have to set up some environment variables.
– Rob
May 1 '11 at 10:46
1
Nobody mentions the traditional:./path/to/yourscript.sh
(without the space after.
)? I find that one is the simplest and easiest to use... But anyways, here is my alternative that should do almost the same as./
would, though I don't see why you wouldn't use./
:(FILENAME=~/rem4space.sh;SLL=$(cat $FILENAME|head -1|sed 's:^#!(.*):1:g');[ ! -z $SLL ] && exec $SLL $FILENAME;sh $FILENAME)
... editFILENAME
to your liking. Also note thatsh
will be used if there is no alternative.
– MiJyn
Jun 19 '13 at 3:50
add a comment |
Give execute permission to your script:
chmod +x /path/to/yourscript.sh
And to run your script:
/path/to/yourscript.sh
Since .
refers to the current directory: if yourscript.sh
is in the current directory, you can simplify this to:
./yourscript.sh
13
+1 only answer to show adding execute permissions in a terminal only way.
– Hailwood
May 1 '11 at 3:24
69
If you dobash /path/to/yourscript.sh
then you don't needchmod +x
– Aleksandr Levchuk
May 1 '11 at 4:51
3
Actually, you can use. /path/to/yourscript.sh
if the script have to set up some environment variables.
– Rob
May 1 '11 at 10:46
1
Nobody mentions the traditional:./path/to/yourscript.sh
(without the space after.
)? I find that one is the simplest and easiest to use... But anyways, here is my alternative that should do almost the same as./
would, though I don't see why you wouldn't use./
:(FILENAME=~/rem4space.sh;SLL=$(cat $FILENAME|head -1|sed 's:^#!(.*):1:g');[ ! -z $SLL ] && exec $SLL $FILENAME;sh $FILENAME)
... editFILENAME
to your liking. Also note thatsh
will be used if there is no alternative.
– MiJyn
Jun 19 '13 at 3:50
add a comment |
Give execute permission to your script:
chmod +x /path/to/yourscript.sh
And to run your script:
/path/to/yourscript.sh
Since .
refers to the current directory: if yourscript.sh
is in the current directory, you can simplify this to:
./yourscript.sh
Give execute permission to your script:
chmod +x /path/to/yourscript.sh
And to run your script:
/path/to/yourscript.sh
Since .
refers to the current directory: if yourscript.sh
is in the current directory, you can simplify this to:
./yourscript.sh
edited Jun 18 '15 at 7:53
Jeremy Kerr
19.2k34058
19.2k34058
answered May 1 '11 at 3:18
karthick87karthick87
48k53166217
48k53166217
13
+1 only answer to show adding execute permissions in a terminal only way.
– Hailwood
May 1 '11 at 3:24
69
If you dobash /path/to/yourscript.sh
then you don't needchmod +x
– Aleksandr Levchuk
May 1 '11 at 4:51
3
Actually, you can use. /path/to/yourscript.sh
if the script have to set up some environment variables.
– Rob
May 1 '11 at 10:46
1
Nobody mentions the traditional:./path/to/yourscript.sh
(without the space after.
)? I find that one is the simplest and easiest to use... But anyways, here is my alternative that should do almost the same as./
would, though I don't see why you wouldn't use./
:(FILENAME=~/rem4space.sh;SLL=$(cat $FILENAME|head -1|sed 's:^#!(.*):1:g');[ ! -z $SLL ] && exec $SLL $FILENAME;sh $FILENAME)
... editFILENAME
to your liking. Also note thatsh
will be used if there is no alternative.
– MiJyn
Jun 19 '13 at 3:50
add a comment |
13
+1 only answer to show adding execute permissions in a terminal only way.
– Hailwood
May 1 '11 at 3:24
69
If you dobash /path/to/yourscript.sh
then you don't needchmod +x
– Aleksandr Levchuk
May 1 '11 at 4:51
3
Actually, you can use. /path/to/yourscript.sh
if the script have to set up some environment variables.
– Rob
May 1 '11 at 10:46
1
Nobody mentions the traditional:./path/to/yourscript.sh
(without the space after.
)? I find that one is the simplest and easiest to use... But anyways, here is my alternative that should do almost the same as./
would, though I don't see why you wouldn't use./
:(FILENAME=~/rem4space.sh;SLL=$(cat $FILENAME|head -1|sed 's:^#!(.*):1:g');[ ! -z $SLL ] && exec $SLL $FILENAME;sh $FILENAME)
... editFILENAME
to your liking. Also note thatsh
will be used if there is no alternative.
– MiJyn
Jun 19 '13 at 3:50
13
13
+1 only answer to show adding execute permissions in a terminal only way.
– Hailwood
May 1 '11 at 3:24
+1 only answer to show adding execute permissions in a terminal only way.
– Hailwood
May 1 '11 at 3:24
69
69
If you do
bash /path/to/yourscript.sh
then you don't need chmod +x
– Aleksandr Levchuk
May 1 '11 at 4:51
If you do
bash /path/to/yourscript.sh
then you don't need chmod +x
– Aleksandr Levchuk
May 1 '11 at 4:51
3
3
Actually, you can use
. /path/to/yourscript.sh
if the script have to set up some environment variables.– Rob
May 1 '11 at 10:46
Actually, you can use
. /path/to/yourscript.sh
if the script have to set up some environment variables.– Rob
May 1 '11 at 10:46
1
1
Nobody mentions the traditional:
./path/to/yourscript.sh
(without the space after .
)? I find that one is the simplest and easiest to use... But anyways, here is my alternative that should do almost the same as ./
would, though I don't see why you wouldn't use ./
: (FILENAME=~/rem4space.sh;SLL=$(cat $FILENAME|head -1|sed 's:^#!(.*):1:g');[ ! -z $SLL ] && exec $SLL $FILENAME;sh $FILENAME)
... edit FILENAME
to your liking. Also note that sh
will be used if there is no alternative.– MiJyn
Jun 19 '13 at 3:50
Nobody mentions the traditional:
./path/to/yourscript.sh
(without the space after .
)? I find that one is the simplest and easiest to use... But anyways, here is my alternative that should do almost the same as ./
would, though I don't see why you wouldn't use ./
: (FILENAME=~/rem4space.sh;SLL=$(cat $FILENAME|head -1|sed 's:^#!(.*):1:g');[ ! -z $SLL ] && exec $SLL $FILENAME;sh $FILENAME)
... edit FILENAME
to your liking. Also note that sh
will be used if there is no alternative.– MiJyn
Jun 19 '13 at 3:50
add a comment |
You need to mark shell scripts as executable to run them from the file manager:
Right click on your
.sh
file and select Properties:
In the Permissions tab, check Allow executing file as program:
Close the Properties window and double-click the file. A dialog will pop up giving you the option to run the script in a terminal:
8
This isn't working in Ubuntu 13.04. Keeps opening in gedit anyway, never asks me to execute. Edit: Nvm, imjustmatthew answers this.
– mpen
Jul 12 '13 at 16:27
Before using this we need to make the file permission for execute using chmod. chmod +x filename.sh or chmod 755 filename.sh
– Arvind Rawat
Mar 16 '17 at 15:11
I don't have popup! IDE is opened straight away, not a popup
– Green
Apr 4 '18 at 10:56
How come I can't find "run in terminal" anywhere on my interface? (Ubuntu 18.04)
– Daniel Möller
May 9 '18 at 22:08
1
@DanielMöller, here is the answer to your question. askubuntu.com/questions/38661/how-do-i-run-sh-files/…
– Akhilesh Dhar Dubey
Aug 16 '18 at 10:19
|
show 1 more comment
You need to mark shell scripts as executable to run them from the file manager:
Right click on your
.sh
file and select Properties:
In the Permissions tab, check Allow executing file as program:
Close the Properties window and double-click the file. A dialog will pop up giving you the option to run the script in a terminal:
8
This isn't working in Ubuntu 13.04. Keeps opening in gedit anyway, never asks me to execute. Edit: Nvm, imjustmatthew answers this.
– mpen
Jul 12 '13 at 16:27
Before using this we need to make the file permission for execute using chmod. chmod +x filename.sh or chmod 755 filename.sh
– Arvind Rawat
Mar 16 '17 at 15:11
I don't have popup! IDE is opened straight away, not a popup
– Green
Apr 4 '18 at 10:56
How come I can't find "run in terminal" anywhere on my interface? (Ubuntu 18.04)
– Daniel Möller
May 9 '18 at 22:08
1
@DanielMöller, here is the answer to your question. askubuntu.com/questions/38661/how-do-i-run-sh-files/…
– Akhilesh Dhar Dubey
Aug 16 '18 at 10:19
|
show 1 more comment
You need to mark shell scripts as executable to run them from the file manager:
Right click on your
.sh
file and select Properties:
In the Permissions tab, check Allow executing file as program:
Close the Properties window and double-click the file. A dialog will pop up giving you the option to run the script in a terminal:
You need to mark shell scripts as executable to run them from the file manager:
Right click on your
.sh
file and select Properties:
In the Permissions tab, check Allow executing file as program:
Close the Properties window and double-click the file. A dialog will pop up giving you the option to run the script in a terminal:
answered May 1 '11 at 3:02
IsaiahIsaiah
43k20118138
43k20118138
8
This isn't working in Ubuntu 13.04. Keeps opening in gedit anyway, never asks me to execute. Edit: Nvm, imjustmatthew answers this.
– mpen
Jul 12 '13 at 16:27
Before using this we need to make the file permission for execute using chmod. chmod +x filename.sh or chmod 755 filename.sh
– Arvind Rawat
Mar 16 '17 at 15:11
I don't have popup! IDE is opened straight away, not a popup
– Green
Apr 4 '18 at 10:56
How come I can't find "run in terminal" anywhere on my interface? (Ubuntu 18.04)
– Daniel Möller
May 9 '18 at 22:08
1
@DanielMöller, here is the answer to your question. askubuntu.com/questions/38661/how-do-i-run-sh-files/…
– Akhilesh Dhar Dubey
Aug 16 '18 at 10:19
|
show 1 more comment
8
This isn't working in Ubuntu 13.04. Keeps opening in gedit anyway, never asks me to execute. Edit: Nvm, imjustmatthew answers this.
– mpen
Jul 12 '13 at 16:27
Before using this we need to make the file permission for execute using chmod. chmod +x filename.sh or chmod 755 filename.sh
– Arvind Rawat
Mar 16 '17 at 15:11
I don't have popup! IDE is opened straight away, not a popup
– Green
Apr 4 '18 at 10:56
How come I can't find "run in terminal" anywhere on my interface? (Ubuntu 18.04)
– Daniel Möller
May 9 '18 at 22:08
1
@DanielMöller, here is the answer to your question. askubuntu.com/questions/38661/how-do-i-run-sh-files/…
– Akhilesh Dhar Dubey
Aug 16 '18 at 10:19
8
8
This isn't working in Ubuntu 13.04. Keeps opening in gedit anyway, never asks me to execute. Edit: Nvm, imjustmatthew answers this.
– mpen
Jul 12 '13 at 16:27
This isn't working in Ubuntu 13.04. Keeps opening in gedit anyway, never asks me to execute. Edit: Nvm, imjustmatthew answers this.
– mpen
Jul 12 '13 at 16:27
Before using this we need to make the file permission for execute using chmod. chmod +x filename.sh or chmod 755 filename.sh
– Arvind Rawat
Mar 16 '17 at 15:11
Before using this we need to make the file permission for execute using chmod. chmod +x filename.sh or chmod 755 filename.sh
– Arvind Rawat
Mar 16 '17 at 15:11
I don't have popup! IDE is opened straight away, not a popup
– Green
Apr 4 '18 at 10:56
I don't have popup! IDE is opened straight away, not a popup
– Green
Apr 4 '18 at 10:56
How come I can't find "run in terminal" anywhere on my interface? (Ubuntu 18.04)
– Daniel Möller
May 9 '18 at 22:08
How come I can't find "run in terminal" anywhere on my interface? (Ubuntu 18.04)
– Daniel Möller
May 9 '18 at 22:08
1
1
@DanielMöller, here is the answer to your question. askubuntu.com/questions/38661/how-do-i-run-sh-files/…
– Akhilesh Dhar Dubey
Aug 16 '18 at 10:19
@DanielMöller, here is the answer to your question. askubuntu.com/questions/38661/how-do-i-run-sh-files/…
– Akhilesh Dhar Dubey
Aug 16 '18 at 10:19
|
show 1 more comment
Prerequisite
Before you can run the .sh file, you need to make it executable:
- Right-click on the file
- Select Properties
- Select Permissions
- Select Allow executing file as a program
Warning
Make sure you trust the source where you got the file from. It could be a virus.
The very simple way
- Double-click on the file
- Click run in terminal
This has problem. The terminal will close immediately and you will not be able to see the output.
The simple way
- Open Applications -> Accessories -> Terminal
- Drag and drop the .sh file into the terminal and press Enter
The way professionals do it
- Open Applications -> Accessories -> Terminal
Find where the .sh file
- Use the
ls
andcd
commands
ls
will list the files and folders in the current folder. Give it a try: type "ls" and press Enter.- Once you see the folder that you want to go in to, run
cd
, followed by a space, followed by a folder name - If you when into a folder that you did not want, run
cd ..
to go one level up
- Use the
Run the .sh file
Once you can see for example
script1.sh
withls
run this:
./script.sh
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 ls
and cd
. Once you are in the correct current folder you can run the script like this:
./script1.sh
or you can run and redirect the output to a file:
./script1.sh > out.txt
or you can filter the output for keywords (e.g. "apples") an then redirect to a file:
./script1.sh | grep apples > ./only-apples
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:
wget www.google.com/images/logos/ps_logo2.png
And then open the file like this:
shotwell ps_logo2.png
5
Im not sure that The way professionals do it is correct, it's more a case of the simple way the advanced(for for control of output) way
– Hailwood
May 1 '11 at 4:24
add a comment |
Prerequisite
Before you can run the .sh file, you need to make it executable:
- Right-click on the file
- Select Properties
- Select Permissions
- Select Allow executing file as a program
Warning
Make sure you trust the source where you got the file from. It could be a virus.
The very simple way
- Double-click on the file
- Click run in terminal
This has problem. The terminal will close immediately and you will not be able to see the output.
The simple way
- Open Applications -> Accessories -> Terminal
- Drag and drop the .sh file into the terminal and press Enter
The way professionals do it
- Open Applications -> Accessories -> Terminal
Find where the .sh file
- Use the
ls
andcd
commands
ls
will list the files and folders in the current folder. Give it a try: type "ls" and press Enter.- Once you see the folder that you want to go in to, run
cd
, followed by a space, followed by a folder name - If you when into a folder that you did not want, run
cd ..
to go one level up
- Use the
Run the .sh file
Once you can see for example
script1.sh
withls
run this:
./script.sh
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 ls
and cd
. Once you are in the correct current folder you can run the script like this:
./script1.sh
or you can run and redirect the output to a file:
./script1.sh > out.txt
or you can filter the output for keywords (e.g. "apples") an then redirect to a file:
./script1.sh | grep apples > ./only-apples
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:
wget www.google.com/images/logos/ps_logo2.png
And then open the file like this:
shotwell ps_logo2.png
5
Im not sure that The way professionals do it is correct, it's more a case of the simple way the advanced(for for control of output) way
– Hailwood
May 1 '11 at 4:24
add a comment |
Prerequisite
Before you can run the .sh file, you need to make it executable:
- Right-click on the file
- Select Properties
- Select Permissions
- Select Allow executing file as a program
Warning
Make sure you trust the source where you got the file from. It could be a virus.
The very simple way
- Double-click on the file
- Click run in terminal
This has problem. The terminal will close immediately and you will not be able to see the output.
The simple way
- Open Applications -> Accessories -> Terminal
- Drag and drop the .sh file into the terminal and press Enter
The way professionals do it
- Open Applications -> Accessories -> Terminal
Find where the .sh file
- Use the
ls
andcd
commands
ls
will list the files and folders in the current folder. Give it a try: type "ls" and press Enter.- Once you see the folder that you want to go in to, run
cd
, followed by a space, followed by a folder name - If you when into a folder that you did not want, run
cd ..
to go one level up
- Use the
Run the .sh file
Once you can see for example
script1.sh
withls
run this:
./script.sh
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 ls
and cd
. Once you are in the correct current folder you can run the script like this:
./script1.sh
or you can run and redirect the output to a file:
./script1.sh > out.txt
or you can filter the output for keywords (e.g. "apples") an then redirect to a file:
./script1.sh | grep apples > ./only-apples
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:
wget www.google.com/images/logos/ps_logo2.png
And then open the file like this:
shotwell ps_logo2.png
Prerequisite
Before you can run the .sh file, you need to make it executable:
- Right-click on the file
- Select Properties
- Select Permissions
- Select Allow executing file as a program
Warning
Make sure you trust the source where you got the file from. It could be a virus.
The very simple way
- Double-click on the file
- Click run in terminal
This has problem. The terminal will close immediately and you will not be able to see the output.
The simple way
- Open Applications -> Accessories -> Terminal
- Drag and drop the .sh file into the terminal and press Enter
The way professionals do it
- Open Applications -> Accessories -> Terminal
Find where the .sh file
- Use the
ls
andcd
commands
ls
will list the files and folders in the current folder. Give it a try: type "ls" and press Enter.- Once you see the folder that you want to go in to, run
cd
, followed by a space, followed by a folder name - If you when into a folder that you did not want, run
cd ..
to go one level up
- Use the
Run the .sh file
Once you can see for example
script1.sh
withls
run this:
./script.sh
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 ls
and cd
. Once you are in the correct current folder you can run the script like this:
./script1.sh
or you can run and redirect the output to a file:
./script1.sh > out.txt
or you can filter the output for keywords (e.g. "apples") an then redirect to a file:
./script1.sh | grep apples > ./only-apples
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:
wget www.google.com/images/logos/ps_logo2.png
And then open the file like this:
shotwell ps_logo2.png
edited May 1 '11 at 3:37
answered May 1 '11 at 2:52
Aleksandr LevchukAleksandr Levchuk
1,5231920
1,5231920
5
Im not sure that The way professionals do it is correct, it's more a case of the simple way the advanced(for for control of output) way
– Hailwood
May 1 '11 at 4:24
add a comment |
5
Im not sure that The way professionals do it is correct, it's more a case of the simple way the advanced(for for control of output) way
– Hailwood
May 1 '11 at 4:24
5
5
Im not sure that The way professionals do it is correct, it's more a case of the simple way the advanced(for for control of output) way
– Hailwood
May 1 '11 at 4:24
Im not sure that The way professionals do it is correct, it's more a case of the simple way the advanced(for for control of output) way
– Hailwood
May 1 '11 at 4:24
add a comment |
Open a terminal and navigate to the folder where the .sh
file is located. Then type:
sh <name of file>.sh
add a comment |
Open a terminal and navigate to the folder where the .sh
file is located. Then type:
sh <name of file>.sh
add a comment |
Open a terminal and navigate to the folder where the .sh
file is located. Then type:
sh <name of file>.sh
Open a terminal and navigate to the folder where the .sh
file is located. Then type:
sh <name of file>.sh
edited Jun 11 '13 at 1:06
edwin
3,3001430
3,3001430
answered Dec 20 '12 at 7:43
italianfootitalianfoot
30923
30923
add a comment |
add a comment |
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.
The person who asked the question is talking about Ubuntu 10.10
– edwin
Jun 11 '13 at 0:48
1
Thank you!!! I don't know why they'd change this, couldn't figure out how to execute anything.
– mpen
Jul 12 '13 at 16:28
1
This is the right answer for latest ubuntus.
– gaRex
Apr 11 '15 at 11:44
How do you get to Nautilus in 15.10?
– Yaakov Ainspan
May 23 '16 at 17:54
As of Ubuntu 18.04, you can access the preferences by opening a directory and then clicking "Files -> Preferences" in the top bar.
– tparker
Nov 17 '18 at 20:04
add a comment |
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.
The person who asked the question is talking about Ubuntu 10.10
– edwin
Jun 11 '13 at 0:48
1
Thank you!!! I don't know why they'd change this, couldn't figure out how to execute anything.
– mpen
Jul 12 '13 at 16:28
1
This is the right answer for latest ubuntus.
– gaRex
Apr 11 '15 at 11:44
How do you get to Nautilus in 15.10?
– Yaakov Ainspan
May 23 '16 at 17:54
As of Ubuntu 18.04, you can access the preferences by opening a directory and then clicking "Files -> Preferences" in the top bar.
– tparker
Nov 17 '18 at 20:04
add a comment |
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.
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.
edited Jun 16 '15 at 11:23
kos
25.4k870120
25.4k870120
answered Jun 10 '13 at 21:41
imjustmatthewimjustmatthew
18114
18114
The person who asked the question is talking about Ubuntu 10.10
– edwin
Jun 11 '13 at 0:48
1
Thank you!!! I don't know why they'd change this, couldn't figure out how to execute anything.
– mpen
Jul 12 '13 at 16:28
1
This is the right answer for latest ubuntus.
– gaRex
Apr 11 '15 at 11:44
How do you get to Nautilus in 15.10?
– Yaakov Ainspan
May 23 '16 at 17:54
As of Ubuntu 18.04, you can access the preferences by opening a directory and then clicking "Files -> Preferences" in the top bar.
– tparker
Nov 17 '18 at 20:04
add a comment |
The person who asked the question is talking about Ubuntu 10.10
– edwin
Jun 11 '13 at 0:48
1
Thank you!!! I don't know why they'd change this, couldn't figure out how to execute anything.
– mpen
Jul 12 '13 at 16:28
1
This is the right answer for latest ubuntus.
– gaRex
Apr 11 '15 at 11:44
How do you get to Nautilus in 15.10?
– Yaakov Ainspan
May 23 '16 at 17:54
As of Ubuntu 18.04, you can access the preferences by opening a directory and then clicking "Files -> Preferences" in the top bar.
– tparker
Nov 17 '18 at 20:04
The person who asked the question is talking about Ubuntu 10.10
– edwin
Jun 11 '13 at 0:48
The person who asked the question is talking about Ubuntu 10.10
– edwin
Jun 11 '13 at 0:48
1
1
Thank you!!! I don't know why they'd change this, couldn't figure out how to execute anything.
– mpen
Jul 12 '13 at 16:28
Thank you!!! I don't know why they'd change this, couldn't figure out how to execute anything.
– mpen
Jul 12 '13 at 16:28
1
1
This is the right answer for latest ubuntus.
– gaRex
Apr 11 '15 at 11:44
This is the right answer for latest ubuntus.
– gaRex
Apr 11 '15 at 11:44
How do you get to Nautilus in 15.10?
– Yaakov Ainspan
May 23 '16 at 17:54
How do you get to Nautilus in 15.10?
– Yaakov Ainspan
May 23 '16 at 17:54
As of Ubuntu 18.04, you can access the preferences by opening a directory and then clicking "Files -> Preferences" in the top bar.
– tparker
Nov 17 '18 at 20:04
As of Ubuntu 18.04, you can access the preferences by opening a directory and then clicking "Files -> Preferences" in the top bar.
– tparker
Nov 17 '18 at 20:04
add a comment |
Go to the directory where the .sh
file is by using cd
. In this example I have stored my sh
file as ~/Desktop/shell_practice/test.sh
first do pwd
to figure out where you are, and if it returns /home/username
(where username
is your real username), you can run
cd Desktop/shell/practice
If you seem to be somewhere else, you can use the absolute path
cd ~/Desktop/shell/practice
or
cd $HOME/Desktop/shell/practice
or even
cd /home/$USER/Desktop/shell/practice
these are all ways of describing the same place. Once you've made it to the location of your script, type
ls
If you can see the sh
file in the output, you can use chmod
to make it executable. In my case, remember, the filename is test.sh
, so I would run
chmod u+x test.sh
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 ./
(the current directory followed by a path separator, to distinguish it from the filename). To run my file I would type:
./test.sh
If your script has been written correctly it will run without errors...
Here's a live example:
This worked for me to install Netbeans on ubuntu
– RuD3B0y
Jan 6 '18 at 20:16
Wb, @RuD3B0y, i tried to keep the answers best for noobs, no high tech content, if you have some edits you are welcome.
– TheExorcist
Apr 2 '18 at 17:58
add a comment |
Go to the directory where the .sh
file is by using cd
. In this example I have stored my sh
file as ~/Desktop/shell_practice/test.sh
first do pwd
to figure out where you are, and if it returns /home/username
(where username
is your real username), you can run
cd Desktop/shell/practice
If you seem to be somewhere else, you can use the absolute path
cd ~/Desktop/shell/practice
or
cd $HOME/Desktop/shell/practice
or even
cd /home/$USER/Desktop/shell/practice
these are all ways of describing the same place. Once you've made it to the location of your script, type
ls
If you can see the sh
file in the output, you can use chmod
to make it executable. In my case, remember, the filename is test.sh
, so I would run
chmod u+x test.sh
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 ./
(the current directory followed by a path separator, to distinguish it from the filename). To run my file I would type:
./test.sh
If your script has been written correctly it will run without errors...
Here's a live example:
This worked for me to install Netbeans on ubuntu
– RuD3B0y
Jan 6 '18 at 20:16
Wb, @RuD3B0y, i tried to keep the answers best for noobs, no high tech content, if you have some edits you are welcome.
– TheExorcist
Apr 2 '18 at 17:58
add a comment |
Go to the directory where the .sh
file is by using cd
. In this example I have stored my sh
file as ~/Desktop/shell_practice/test.sh
first do pwd
to figure out where you are, and if it returns /home/username
(where username
is your real username), you can run
cd Desktop/shell/practice
If you seem to be somewhere else, you can use the absolute path
cd ~/Desktop/shell/practice
or
cd $HOME/Desktop/shell/practice
or even
cd /home/$USER/Desktop/shell/practice
these are all ways of describing the same place. Once you've made it to the location of your script, type
ls
If you can see the sh
file in the output, you can use chmod
to make it executable. In my case, remember, the filename is test.sh
, so I would run
chmod u+x test.sh
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 ./
(the current directory followed by a path separator, to distinguish it from the filename). To run my file I would type:
./test.sh
If your script has been written correctly it will run without errors...
Here's a live example:
Go to the directory where the .sh
file is by using cd
. In this example I have stored my sh
file as ~/Desktop/shell_practice/test.sh
first do pwd
to figure out where you are, and if it returns /home/username
(where username
is your real username), you can run
cd Desktop/shell/practice
If you seem to be somewhere else, you can use the absolute path
cd ~/Desktop/shell/practice
or
cd $HOME/Desktop/shell/practice
or even
cd /home/$USER/Desktop/shell/practice
these are all ways of describing the same place. Once you've made it to the location of your script, type
ls
If you can see the sh
file in the output, you can use chmod
to make it executable. In my case, remember, the filename is test.sh
, so I would run
chmod u+x test.sh
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 ./
(the current directory followed by a path separator, to distinguish it from the filename). To run my file I would type:
./test.sh
If your script has been written correctly it will run without errors...
Here's a live example:
edited Sep 14 '17 at 15:25
Zanna
50.4k13133241
50.4k13133241
answered Dec 3 '16 at 11:14
TheExorcistTheExorcist
16315
16315
This worked for me to install Netbeans on ubuntu
– RuD3B0y
Jan 6 '18 at 20:16
Wb, @RuD3B0y, i tried to keep the answers best for noobs, no high tech content, if you have some edits you are welcome.
– TheExorcist
Apr 2 '18 at 17:58
add a comment |
This worked for me to install Netbeans on ubuntu
– RuD3B0y
Jan 6 '18 at 20:16
Wb, @RuD3B0y, i tried to keep the answers best for noobs, no high tech content, if you have some edits you are welcome.
– TheExorcist
Apr 2 '18 at 17:58
This worked for me to install Netbeans on ubuntu
– RuD3B0y
Jan 6 '18 at 20:16
This worked for me to install Netbeans on ubuntu
– RuD3B0y
Jan 6 '18 at 20:16
Wb, @RuD3B0y, i tried to keep the answers best for noobs, no high tech content, if you have some edits you are welcome.
– TheExorcist
Apr 2 '18 at 17:58
Wb, @RuD3B0y, i tried to keep the answers best for noobs, no high tech content, if you have some edits you are welcome.
– TheExorcist
Apr 2 '18 at 17:58
add a comment |
2 main steps.
in terminal, use gedit to write and save script with ".sh" extension to desktop.
(but any text editor can be used)
open Nautilus and right click the script.sh file.
under properties, check box "allow executing file.."
in Nautilus menu, click file,then preferences,then behaviour
check the "run executable text files when they are opened".
Now, when you double click the file on the desktop, it should execute.
no need for .
or ./
add a comment |
2 main steps.
in terminal, use gedit to write and save script with ".sh" extension to desktop.
(but any text editor can be used)
open Nautilus and right click the script.sh file.
under properties, check box "allow executing file.."
in Nautilus menu, click file,then preferences,then behaviour
check the "run executable text files when they are opened".
Now, when you double click the file on the desktop, it should execute.
no need for .
or ./
add a comment |
2 main steps.
in terminal, use gedit to write and save script with ".sh" extension to desktop.
(but any text editor can be used)
open Nautilus and right click the script.sh file.
under properties, check box "allow executing file.."
in Nautilus menu, click file,then preferences,then behaviour
check the "run executable text files when they are opened".
Now, when you double click the file on the desktop, it should execute.
no need for .
or ./
2 main steps.
in terminal, use gedit to write and save script with ".sh" extension to desktop.
(but any text editor can be used)
open Nautilus and right click the script.sh file.
under properties, check box "allow executing file.."
in Nautilus menu, click file,then preferences,then behaviour
check the "run executable text files when they are opened".
Now, when you double click the file on the desktop, it should execute.
no need for .
or ./
edited Oct 24 '13 at 15:17
Joren
3,53663151
3,53663151
answered Oct 24 '13 at 14:24
robrob
311
311
add a comment |
add a comment |
In Ubuntu 16.04 this is how to open it in Terminal:
Go to the File Manager > Edit > Preferences > Behavior
for Executable Text Files
and select Ask each time
.
The problem is that it's by default set to View Executable Files when they are opened
.
add a comment |
In Ubuntu 16.04 this is how to open it in Terminal:
Go to the File Manager > Edit > Preferences > Behavior
for Executable Text Files
and select Ask each time
.
The problem is that it's by default set to View Executable Files when they are opened
.
add a comment |
In Ubuntu 16.04 this is how to open it in Terminal:
Go to the File Manager > Edit > Preferences > Behavior
for Executable Text Files
and select Ask each time
.
The problem is that it's by default set to View Executable Files when they are opened
.
In Ubuntu 16.04 this is how to open it in Terminal:
Go to the File Manager > Edit > Preferences > Behavior
for Executable Text Files
and select Ask each time
.
The problem is that it's by default set to View Executable Files when they are opened
.
answered Dec 11 '16 at 19:58
Leniel MaccaferriLeniel Maccaferri
1214
1214
add a comment |
add a comment |
Right-click the
.sh
file and make it executable.Open a terminal (Ctrl+Alt+T).
Drag the
.sh
file into the terminal window and watch in awe.
1
Welcome to Ask Ubuntu! I recommend to edit this answer to expand it with specific details about how to do the first step. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on AskUbuntu.)
– David Foerster
Jun 10 '17 at 15:49
add a comment |
Right-click the
.sh
file and make it executable.Open a terminal (Ctrl+Alt+T).
Drag the
.sh
file into the terminal window and watch in awe.
1
Welcome to Ask Ubuntu! I recommend to edit this answer to expand it with specific details about how to do the first step. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on AskUbuntu.)
– David Foerster
Jun 10 '17 at 15:49
add a comment |
Right-click the
.sh
file and make it executable.Open a terminal (Ctrl+Alt+T).
Drag the
.sh
file into the terminal window and watch in awe.
Right-click the
.sh
file and make it executable.Open a terminal (Ctrl+Alt+T).
Drag the
.sh
file into the terminal window and watch in awe.
edited Jun 10 '17 at 15:49
David Foerster
27.9k1364110
27.9k1364110
answered Jun 10 '17 at 14:09
1p_bunny1p_bunny
211
211
1
Welcome to Ask Ubuntu! I recommend to edit this answer to expand it with specific details about how to do the first step. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on AskUbuntu.)
– David Foerster
Jun 10 '17 at 15:49
add a comment |
1
Welcome to Ask Ubuntu! I recommend to edit this answer to expand it with specific details about how to do the first step. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on AskUbuntu.)
– David Foerster
Jun 10 '17 at 15:49
1
1
Welcome to Ask Ubuntu! I recommend to edit this answer to expand it with specific details about how to do the first step. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on AskUbuntu.)
– David Foerster
Jun 10 '17 at 15:49
Welcome to Ask Ubuntu! I recommend to edit this answer to expand it with specific details about how to do the first step. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on AskUbuntu.)
– David Foerster
Jun 10 '17 at 15:49
add a comment |
There are a few ways to do this.
Option 1
In the terminal, access the directory the Bash file is in using
cd
(change directory).
Ex.
cd Downloads
Run
bash <filename>.sh
This also works with .run files. There is an example of this usage at this webpage on updating Rhythmbox.
Option 2
In the terminal, navigate to the directory the bash file is in.
Run
chmod +x <filename>.sh
In Nautilus, open the file.
add a comment |
There are a few ways to do this.
Option 1
In the terminal, access the directory the Bash file is in using
cd
(change directory).
Ex.
cd Downloads
Run
bash <filename>.sh
This also works with .run files. There is an example of this usage at this webpage on updating Rhythmbox.
Option 2
In the terminal, navigate to the directory the bash file is in.
Run
chmod +x <filename>.sh
In Nautilus, open the file.
add a comment |
There are a few ways to do this.
Option 1
In the terminal, access the directory the Bash file is in using
cd
(change directory).
Ex.
cd Downloads
Run
bash <filename>.sh
This also works with .run files. There is an example of this usage at this webpage on updating Rhythmbox.
Option 2
In the terminal, navigate to the directory the bash file is in.
Run
chmod +x <filename>.sh
In Nautilus, open the file.
There are a few ways to do this.
Option 1
In the terminal, access the directory the Bash file is in using
cd
(change directory).
Ex.
cd Downloads
Run
bash <filename>.sh
This also works with .run files. There is an example of this usage at this webpage on updating Rhythmbox.
Option 2
In the terminal, navigate to the directory the bash file is in.
Run
chmod +x <filename>.sh
In Nautilus, open the file.
edited Sep 14 '17 at 14:47
wjandrea
8,49742259
8,49742259
answered Jan 6 '14 at 21:33
Kenny StierKenny Stier
1057
1057
add a comment |
add a comment |
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:
#!/bin/bash
echo "* UUIDs must match in /etc/fstab and /boot/grub/menu.lst"
sudo blkid
I called the file uuid and placed it in /usr/local/bin. All I need enter on the command line is:
uuid
add a comment |
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:
#!/bin/bash
echo "* UUIDs must match in /etc/fstab and /boot/grub/menu.lst"
sudo blkid
I called the file uuid and placed it in /usr/local/bin. All I need enter on the command line is:
uuid
add a comment |
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:
#!/bin/bash
echo "* UUIDs must match in /etc/fstab and /boot/grub/menu.lst"
sudo blkid
I called the file uuid and placed it in /usr/local/bin. All I need enter on the command line is:
uuid
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:
#!/bin/bash
echo "* UUIDs must match in /etc/fstab and /boot/grub/menu.lst"
sudo blkid
I called the file uuid and placed it in /usr/local/bin. All I need enter on the command line is:
uuid
answered May 1 '11 at 7:14
fragosfragos
2,62721522
2,62721522
add a comment |
add a comment |
For Ubuntu 18.04, There is a little modification, as you don't get a pop-up dialog.
So what you need to do is:
Right click on Files, Select Preferences > Select Behavior Tab > Mark 'Ask what to do' option under Executable text file.
Now, When you double-click on any .sh file, you will get a popup, there you can select "run in terminal" option to run your .sh file.
add a comment |
For Ubuntu 18.04, There is a little modification, as you don't get a pop-up dialog.
So what you need to do is:
Right click on Files, Select Preferences > Select Behavior Tab > Mark 'Ask what to do' option under Executable text file.
Now, When you double-click on any .sh file, you will get a popup, there you can select "run in terminal" option to run your .sh file.
add a comment |
For Ubuntu 18.04, There is a little modification, as you don't get a pop-up dialog.
So what you need to do is:
Right click on Files, Select Preferences > Select Behavior Tab > Mark 'Ask what to do' option under Executable text file.
Now, When you double-click on any .sh file, you will get a popup, there you can select "run in terminal" option to run your .sh file.
For Ubuntu 18.04, There is a little modification, as you don't get a pop-up dialog.
So what you need to do is:
Right click on Files, Select Preferences > Select Behavior Tab > Mark 'Ask what to do' option under Executable text file.
Now, When you double-click on any .sh file, you will get a popup, there you can select "run in terminal" option to run your .sh file.
answered Aug 16 '18 at 10:18
Akhilesh Dhar DubeyAkhilesh Dhar Dubey
1113
1113
add a comment |
add a comment |
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:
- I navigated to the path of the
.sh
file I wanted to execute. - I opened the terminal.
- And I simply dragged and dropped the on the terminal window and it automatically took that file along with the path as input.
- Hit Enter and you are good to go!
add a comment |
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:
- I navigated to the path of the
.sh
file I wanted to execute. - I opened the terminal.
- And I simply dragged and dropped the on the terminal window and it automatically took that file along with the path as input.
- Hit Enter and you are good to go!
add a comment |
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:
- I navigated to the path of the
.sh
file I wanted to execute. - I opened the terminal.
- And I simply dragged and dropped the on the terminal window and it automatically took that file along with the path as input.
- Hit Enter and you are good to go!
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:
- I navigated to the path of the
.sh
file I wanted to execute. - I opened the terminal.
- And I simply dragged and dropped the on the terminal window and it automatically took that file along with the path as input.
- Hit Enter and you are good to go!
edited Jun 16 '16 at 15:44
grooveplex
2,20611433
2,20611433
answered Jun 16 '16 at 15:11
Jen BatesJen Bates
1
1
add a comment |
add a comment |
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).
Install
dconf-editor
sudo apt-get install dconf-editor
Run
dconf-editor
using the user account you want this on, i.e NOT root
dconf-editor
Navigate to the following schema:
org.gnome.nautilus.preferences
Change the default option to not open by default:
Find
executable-text-activation
click the worddisplay
and change toask
that will give you the option to edit, view or run the file going forward
add a comment |
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).
Install
dconf-editor
sudo apt-get install dconf-editor
Run
dconf-editor
using the user account you want this on, i.e NOT root
dconf-editor
Navigate to the following schema:
org.gnome.nautilus.preferences
Change the default option to not open by default:
Find
executable-text-activation
click the worddisplay
and change toask
that will give you the option to edit, view or run the file going forward
add a comment |
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).
Install
dconf-editor
sudo apt-get install dconf-editor
Run
dconf-editor
using the user account you want this on, i.e NOT root
dconf-editor
Navigate to the following schema:
org.gnome.nautilus.preferences
Change the default option to not open by default:
Find
executable-text-activation
click the worddisplay
and change toask
that will give you the option to edit, view or run the file going forward
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).
Install
dconf-editor
sudo apt-get install dconf-editor
Run
dconf-editor
using the user account you want this on, i.e NOT root
dconf-editor
Navigate to the following schema:
org.gnome.nautilus.preferences
Change the default option to not open by default:
Find
executable-text-activation
click the worddisplay
and change toask
that will give you the option to edit, view or run the file going forward
edited Sep 14 '17 at 14:35
wjandrea
8,49742259
8,49742259
answered Dec 22 '13 at 16:06
SniderSnider
1
1
add a comment |
add a comment |
I am a noob in Linux and I just had the same problem. If all else fails:
- Open terminal
- Open the folder containing the .sh file
- Drag and drop the file into the terminal window
- The file's path appears in terminal. Press Enter.
- Voila, your .sh file is run.
add a comment |
I am a noob in Linux and I just had the same problem. If all else fails:
- Open terminal
- Open the folder containing the .sh file
- Drag and drop the file into the terminal window
- The file's path appears in terminal. Press Enter.
- Voila, your .sh file is run.
add a comment |
I am a noob in Linux and I just had the same problem. If all else fails:
- Open terminal
- Open the folder containing the .sh file
- Drag and drop the file into the terminal window
- The file's path appears in terminal. Press Enter.
- Voila, your .sh file is run.
I am a noob in Linux and I just had the same problem. If all else fails:
- Open terminal
- Open the folder containing the .sh file
- Drag and drop the file into the terminal window
- The file's path appears in terminal. Press Enter.
- Voila, your .sh file is run.
edited Sep 14 '17 at 14:44
wjandrea
8,49742259
8,49742259
answered May 7 '17 at 2:19
Linux_noobLinux_noob
1
1
add a comment |
add a comment |
You can also use .
tricks, with the suggestion of other answers.
For example:
chmod +x filename.sh
, assuming you have already gone to the path to file then run the file with any one of these command:
sh filename.sh
./filename.sh
. filename.sh
2
warning: These three commands are not equivalent. If your shebang references a different binary (like Stack), then the third command will try parsing arguments with Bash, which will fail.
– Jezen Thomas
Feb 18 '17 at 11:12
add a comment |
You can also use .
tricks, with the suggestion of other answers.
For example:
chmod +x filename.sh
, assuming you have already gone to the path to file then run the file with any one of these command:
sh filename.sh
./filename.sh
. filename.sh
2
warning: These three commands are not equivalent. If your shebang references a different binary (like Stack), then the third command will try parsing arguments with Bash, which will fail.
– Jezen Thomas
Feb 18 '17 at 11:12
add a comment |
You can also use .
tricks, with the suggestion of other answers.
For example:
chmod +x filename.sh
, assuming you have already gone to the path to file then run the file with any one of these command:
sh filename.sh
./filename.sh
. filename.sh
You can also use .
tricks, with the suggestion of other answers.
For example:
chmod +x filename.sh
, assuming you have already gone to the path to file then run the file with any one of these command:
sh filename.sh
./filename.sh
. filename.sh
answered Jan 2 '15 at 8:29
AwaisAwais
162128
162128
2
warning: These three commands are not equivalent. If your shebang references a different binary (like Stack), then the third command will try parsing arguments with Bash, which will fail.
– Jezen Thomas
Feb 18 '17 at 11:12
add a comment |
2
warning: These three commands are not equivalent. If your shebang references a different binary (like Stack), then the third command will try parsing arguments with Bash, which will fail.
– Jezen Thomas
Feb 18 '17 at 11:12
2
2
warning: These three commands are not equivalent. If your shebang references a different binary (like Stack), then the third command will try parsing arguments with Bash, which will fail.
– Jezen Thomas
Feb 18 '17 at 11:12
warning: These three commands are not equivalent. If your shebang references a different binary (like Stack), then the third command will try parsing arguments with Bash, which will fail.
– Jezen Thomas
Feb 18 '17 at 11:12
add a comment |
protected by Community♦ Aug 21 '18 at 12:25
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Does that script aim to set up env variables for further use?
– Rob
May 1 '11 at 10:47
1
You shouldn't use extensions on scripts. At some point in the future, you may find that a different language is more suitable to do the task your current script is doing. And then you have a problem. Do you keep the old name, with a completely misleading extension, or do you rename it, possibly having to edit alot of places where your script is used?
– geirha
May 1 '11 at 14:07
You don't need the file extension. It's nice to have but is not needed. The OS doesn't look at the file extension. It looks at the data
– ActionParsnip
May 4 '11 at 17:41
5
Meh, if you rewrite foo.sh in ruby, you can always use the .sh file to launch
ruby foo.rb
– glenn jackman
Jun 11 '13 at 1:24
In Dolphin you can press F4 and a console opens
– Motte001
Jun 16 '16 at 16:47