Whenever I open a .sh file, it opens it in gedit instead of the terminal. I can't find any option similar to Right ClickOpen WithOther Application...Terminal.

How do I open this file in the terminal?


Solution 1:

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

Solution 2:

You need to mark shell scripts as executable to run them from the file manager:

  1. Right click on your .sh file and select Properties:

    enter image description here

  2. In the Permissions tab, check Allow executing file as program:

    enter image description here

  3. 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:

    enter image description here

Solution 3:

Open a terminal and navigate to the folder where the .sh file is located. Then type:

sh <name of file>.sh