How to run .sh file from console

Question:

I would like to know why I can not run the .sh file via ./launch.sh
please have a look at the below posted screen-shot

image

enter image description here

Asked By: LetsamrIt

||

Answers:

You need to mark it as an executable program with chmod +x launch.sh, or alternatively execute it with bash: bash launch.sh

Answered By: Wouter De Coster

I think the command would be sh launch.sh

Answered By: David

@Wouter De Coster solve the problem, anyway i´ll try to add a bit more information.

Console Method

Setting Area

To use ./ function, the file must have execute permission on the script.

use chmod +x launch.sh to set that permissions.

Run Area

Try to use ./launch.sh again.

Another options to execute them:

sh launch.sh

bash launch.sh

GUI Method

Setting Area

  1. Select the file using mouse
  2. Right-click on the file
  3. Choose properties

Properties actions

  1. Click Permissions tab
  2. Select Allow executing file as a program:

Properties functions

Run Area

Click the file name and you will be prompted. Select Run in the terminal and it will get executed in the terminal.

Once you changed the properties you can use the Run methods used in Console Method

#EXTRA

You can run .sh file and use debugging options, For example:

To debug shell script. It print commands and their arguments as they are executed.

bash -x launch.sh

To show shell input lines as they are read:

bash -v launch.sh

Answered By: mrCatlost
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.