How to Create and Run Script File in Linux

There are several steps involved in creating and running a bash script. First, you have to create the actual file. Second, you edit the file (adding the code). Finally, you save the file and execute. This video tutorial goes over the steps on how to create and execute a bash script in Linux.

And here’s the transcript of the terminal session

jorge@nixbox ~/test $ vi hello.sh
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ cat hello.sh
#!/bin/bash
#author
#date
#purpose:
echo "Hello World!.."
#END
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ ./hello.sh
bash: ./hello.sh: Permission denied
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ ls -l hello.sh 
-rw-r--r-- 1 jorge jorge 66 Feb 19 15:09 hello.sh
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ chmod +x hello.sh 
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ ls -l hello.sh 
-rwxr-xr-x 1 jorge jorge 66 Feb 19 15:09 hello.sh
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ clear
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $ ./hello.sh 
Hello World!..
jorge@nixbox ~/test $ 
jorge@nixbox ~/test $

Share This!

Leave a Reply

Your email address will not be published.