How do I execute a bash script in Terminal?

匿名 (未验证) 提交于 2019-12-03 01:12:01

问题:

I have a bash script like:

#!/bin/bash  echo Hello world! 

How do I execute this in Terminal?

回答1:

$prompt: /path/to/script and hit enter. Note you need to make sure the script has execute permissions.



回答2:

Yet another way to execute it (this time without setting execute permissions):

bash /path/to/scriptname 


回答3:

You could do:
sh scriptname.sh



回答4:

cd to the directory that contains the script, or put it in a bin folder that is in your $PATH

then type

./scriptname.sh 

if in the same directory or

scriptname.sh 

if it's in the bin folder.



回答5:

Change your directory to where script is located by using cd command

Then type

bash program-name.sh 


回答6:

Firstly you have to make it executable using: chmod +x filename . At the filename you should write the name of you file as it is, for example: helloworld.sh After you made it executable then you can run it using /.filename Hope it helped:)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!