Make .sh file executable
16,891
open the terminal and write the following command
chmod +x filename.sh
Well that gonna make your file executable which can be run from terminal by simple command
sudo ./filename.sh
There is another way of doing it through GUI, when you right click on the file and goto permissions tab then you get an option to make the file executable by just clicking a checkbox
Related videos on Youtube
Author by
Admin
Updated on September 18, 2022Comments
-
Admin over 1 year
I have a .sh file which is not becoming an executable. I tried doing it in the properties but as soon I ticked the checkbox, the tick vanished in a second.
I then tried
sudo chmod +x filename.sh
which returned nothing and after checking its properties, it dint turn into an executable. Any solutions?
-
Alvin Wong over 11 yearsEven if it isn't executable, I guess you can just "execute" it by
. ./filename.sh
? -
Lennart over 11 yearsMaybe the file is still opened in another program? Like gedit or another terminal.
-
tvdo over 10 years@AlvinWong A closer approximation would be
sh ./filename.sh
- using.
(equivalent ofsource
) would parse it in the current shell, rather than spawning a subshell. -
ganesh about 10 years1) @OP: Do you intend to run that script as uid 0 (aka toor, root, admin ,...)? If not, why use
sudo
? 2) What happens if you open a shell, cd to the the directory the script is in and typechmod +x filename.sh
? 3) What is the first line of filename.sh? Is that#!/usr/bin/env bash
or similar?
-
-
selbie over 11 yearsI was just about to type the same thing. I suspect the "./" prefix was getting missed.
-
Azzy over 11 yearsyupp tht was d error... and see that other way too. thtz more easy if you want to work just by GUI. If yu found my answer correct, plz mark it as accepted answer :)
-
Admin over 11 years@Azzy I already tried what you said. Using the GUI, when I clicked the checkbox in the permissions tab, the tick vanished in a second. And when I tried what you said, it returned sudo command not found.
-
stib about 10 yearsyou don't need, and shouldn't use sudo unless you need to run it as root. Have you tried sh ./filename.sh?