How do I execute a bash script in Terminal?
I have a bash script like:
#!/bin/bash
echo Hello world!
How do I execute this in Terminal?
Solution 1:
Yet another way to execute it (this time without setting execute permissions):
bash /path/to/scriptname
Solution 2:
$prompt: /path/to/script
and hit enter. Note you need to make sure the script has execute permissions.
Solution 3:
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.
Solution 4:
You could do:sh scriptname.sh