run bash script code example

Example 1: how to run shell script

chmod +x <fileName>
./fileName.  # or use ->. bash fileName

Example 2: how to execute a bash script in terminal

$ chmod +x fileName
$ ./fileName

Example 3: shell file in linux

#!/bin/sh
ls

Example 4: how to run shell script

include 
#!/bin/bash (1st line inside yourfile.sh)

to run
./yourfile.sh

if you do not include that line
bash yourfile.sh

Example 5: how to run shell script

bash yourfile.sh

Example 6: run sh file

sh yourfile.sh