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

Share:
16,891

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    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
      Alvin Wong over 11 years
      Even if it isn't executable, I guess you can just "execute" it by . ./filename.sh?
    • Lennart
      Lennart over 11 years
      Maybe the file is still opened in another program? Like gedit or another terminal.
    • tvdo
      tvdo over 10 years
      @AlvinWong A closer approximation would be sh ./filename.sh - using . (equivalent of source) would parse it in the current shell, rather than spawning a subshell.
    • ganesh
      ganesh about 10 years
      1) @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 type chmod +x filename.sh? 3) What is the first line of filename.sh? Is that #!/usr/bin/env bash or similar?
  • selbie
    selbie over 11 years
    I was just about to type the same thing. I suspect the "./" prefix was getting missed.
  • Azzy
    Azzy over 11 years
    yupp 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
    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
    stib about 10 years
    you don't need, and shouldn't use sudo unless you need to run it as root. Have you tried sh ./filename.sh?