Notes on shell scripting.

Bash is a Unix shell and command language originally released in 1989. It can read and execute text files called shell script that are useful for automating tasks.

The terminal cheatsheet contains some of the commands that can be run as part of a bash script.

Running a script

Navigate to the directory containing the script and use ./ to execute it.

If the script fails with an permissions error, use chmod 755 to make it executable.

Shebang. Indicates which interpreter a script should be run with: #!/bin/bash

$1, $2, ...
The first, second, etc command line arguments to the script.

To set a value for a variable. Remember, no spaces on either side of =

Quotes " '
Double will do variable substitution, single will not.

if [ ] then else fi
Perform basic conditional logic.

Evaluating the arguments passed to a script

# case example
case $1 in
		echo starting
		echo stoping
		echo restarting
		echo don\'t know


incoming(4) | meta | tablet | terminal shortcuts | photography