How do I execute a bash script in Terminal?

后端 未结 9 2080
無奈伤痛
無奈伤痛 2020-12-12 11:50

I have a bash script like:

#!/bin/bash

echo Hello world!

How do I execute this in Terminal?

9条回答
  •  情话喂你
    2020-12-12 12:21

    If you are in a directory or folder where the script file is available then simply change the file permission in executable mode by doing

    chmod +x your_filename.sh

    After that you will run the script by using the following command.

    $ sudo ./your_filename.sh

    Above the "." represent the current directory. Note! If you are not in the directory where the bash script file is present then you change the directory where the file is located by using

    cd Directory_name/write the complete path

    command. Otherwise your script can not run.

提交回复
热议问题