This document is a straightforward guide for creating a bash script for Mac/Linux.
-
Open up your terminal.
- Create your script file (example:
exampleScript
)1
$ nano exampleScript
- Add a shebang line in the first line of the file.
1
#!/usr/bin/env bash
- Customize your script. In this example we echo “Hello World”.
1 2
#!/usr/bin/env bash echo "Hello World"
-
Exit and save changes in the editor by pressing “CTRL + X”, and “Y” then enter.
- Make the script executable by changing the script permissions.
1
$ chmod +x exampleScript
- Run script
1
$ ./exampleScript
Done!