Write Simple Bash Scripts

First we need to find where is bash interpreter located.
Enter the following into your command line:

$ which bash

Every bash script starts with hashbang:"#!" which is not read as a comment. First line is interpreter location which is in this case: /bin/bash. Here is the simple bash script:

set -xv # set script in debug mood
# it's a comment!

read -p "Do you want to continue? (y/n) " RESP
if [ "$RESP" = "y" ]; then
  echo "running..."
  echo "abort!"

Save in file, give the permission to execute, and run.

$ chmod +x simple_script.sh 
$ ./simple_script.sh.sh

VoilĂ !

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License