Bash and Scripting

"Scripting" is the technique of automating procedures by stringing together commands and saving it all as text files, so called "scripts". Every time you run such a script, the commands are processed one after the other just like they would if you entered them into the Terminal by hand.
Scripts can range from simply executing a few commands in a specific order to sophisticated pieces of code that solve complex tasks.

index The Bash

Since scripts rely naturally a lot on the shell they are interpreted by, you should first familiarize yourself with the BASH that's used by Haiku. There are many resources online as it's a widely used shell. One nice document is Johan Jansson's Introduction to bash - a tutorial for bash under BeOS.
The Bash Reference Manual (PDF, 720 KiB) is a nice resource to get into the details.

index The Scripting Bible

After you've learned a few basics about working in the shell, it's time to slowly ease yourself into the world of scripting. Again, you'll find loads of tutorials and reference material online as well as in bookstores. A very nice introduction that's practically tailor-made for Haiku is the online available Scripting Chapter (PDF, 900 KiB) of Scot Hacker's BeOS Bible.

indexScripts in Haiku

Haiku used to have scripts for booting and shutting down. Today it uses the launch_daemon instead. However, the user can still augment this process with certain user scripts. If they don't exist already, you'll have to create the needed files yourself. Otherwise simply add your commands where in the process you want them to be executed.

index The UserBootscript

/boot/home/config/settings/boot/UserBootscript will be executed after the system has finished its boot process. For example, you could launch a number of programs that would then be automatically started on every boot up:

# Start LaunchBox
/boot/system/apps/LaunchBox &

# Start Workspaces Applet
/boot/system/apps/Workspaces &

Remember to end a command with an "&" to start it as a background process, or the script will halt until that command has finished (in this case: the launched app was closed again).

A simple alternative to the above for launching applications at boot up is to put links to them in the /boot/home/config/settings/boot/launch directory. This can be done simply by right-clicking on the application you wish to have started automatically, going to Create Link and then navigating to the above directory.

index The UserShutdownScript

/boot/home/config/settings/boot/UserShutdownScript will be executed as the first step in the shutdown process. If the script returns a non-zero exit status, the shutdown is aborted.

index The UserShutdownFinishScript

/boot/home/config/settings/boot/UserShutdownFinishScript is executed as the last step in the shutdown process. Note, that most parts of the system have terminated by the time this script is executed.