How to run .sh file
Solution 1
-
copy the file to the desktop (for convenience)
-
Right click on the file and select properties
-
Under permission tab check allow executing file as program
-
double click on the file and chose run in terminal if it is not a gui program)
By default the file manager may not show that option and open the file in gedit instead. In that case change the preference of the file manager at: Edit-> Preferences -> Behaviour to "ask each time" or right away to "run executables"
Command line
cd /path/to/file
chmod +x filename.sh
./filename.sh
Comment below if it wont work :)
If it still won't work, despite having allow executing file as a program ticked, when you double click on the .sh file, and it launches gedit, navigate to the folder with the script.
Once you are in the correct current folder for the script, you can run the script like this:
sudo ./filename.sh
If that doesn't work you may try
sudo bash filename.sh
From FAT partition
Follow this How do I execute a file from a FAT USB drive?
Solution 2
Command line
Apart from what liquid had recommended, usual procedure is to change permissions to make this file executable:
chmod +x file.sh
And then execute this file:
./file.sh
GUI
The same can be achieved in Nautilus file browser using context menu by changing Execute
flags in Properties
-> Permissions
.
Solution 3
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
Solution 4
Try sh nameoffile.sh
in terminal (making sure you are in the folder where nameoffile.sh
is saved)
Related videos on Youtube
Atladica
Updated on September 18, 2022Comments
-
Atladica almost 2 years
Possible Duplicate:
How do I run .sh files in Terminal?I want to download JDownloader from the internet for Linux. But the file is .sh and when I tell ubuntu to open the file it uses some text editor. I searched Ubuntu Software Store and there was no application to open it. Is there any way I can get it installed?
-
arximughal over 8 yearssimply drag the file inside the terminal and hit return key. installation will begin.
-
-
Thomas Ward almost 12 yearsTypically though, .sh files do need to be run in the terminal.
-
domen over 11 yearsThe last one,
.
might not be what you want, since the variables and functions from the script will remain in your current shell. -
dodohjk about 11 yearscommand line work but how can I run it with a double click? doesn't show the option "open with terminal"
-
aldrin about 11 years@dodohjk, (in Ubuntu 13.04) there is an option that controls this - File > PReferences > Behavior > Executable Text Files
-
Cody almost 10 yearsJust an FYI, I had to copy my file to another directory before this worked.
-
Tachyons almost 10 years@Cody : To which directory??
-
Cody almost 10 yearsI was following the command line instructions and trying to do this on a mounted USB drive. It failed to unpack until I copied it over to my desktop.
-
Tachyons almost 10 years@Cody : That is because your USB drive is in either NTFS or FAT format . They do not support Linux permissions :-)
-
Tachyons almost 10 years@Cody Read this too askubuntu.com/questions/23128/…
-
Cody almost 10 yearsThat's good to know. It was in FAT format, you're correct.
-
Paritosh about 9 yearsI am getting problem saying "Unable to locate the program". However, if I run program using
shell
it works fine.