Wednesday, April 27, 2016

How to create Bash Script on Mac

  1. Create the bash script file.
    Sample: File myscript.sh
    #!/bin/bash     #”hash-bang" or “she-bang" indicating that this script is to be interpreted and run by the bash shell
    echo hello world     #prints “hello world”
    
  2. Change the file permission to make it an executable. Open the terminal, navigate to the location of the file and type the following command:
    chmod 700 myscript.sh 
    See this link for more info on chmod: http://www.thinkplexx.com/learn/article/unix/command/chmod-permissions-flags-explained-600-0600-700-777-100-etc
  3. Run the script. Type the following in the terminal:
    ./myscript.sh

No comments:

Post a Comment