<divclass="box-info">Tłumaczenie tej strony jest niekompletne. Nieukończone części wyświetlane są w języku angielskim.</div>
<h1>Bash and Scripting</h1>
<p>"Scripting" to technika automatyzacji zadań zlecanych systemowi operacyjnemu poprzez zapisanie komend w pliku tekstowym zwanym skryptem. W każdym momencie kiedy wykonujesz skrypt komendy w nim zawarte wykonywane są jedna za drugą tak jakbyś ręcznie wprowadzał je z <ahref="applications/terminal.html">Terminala</a>.<br/>
Skrypty mogą być prostymi plikami wykonującymi kilka komend w określonym porządku lub wyrafinowanymi kawałkami kodu rozwiązującymi złożone zadania.</p>
<p>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 <ahref="https://web.archive.org/web/20011205095723/http://www.beforever.com/bashtut.htm"class="printurl">Introduction to bash - a tutorial for bash under BeOS</a>.<br/>
The <ahref="https://www.gnu.org/software/bash/manual/bash.pdf"class="printurl">Bash Reference Manual (PDF, 720 KiB)</a> is a nice resource to get into the details.</p>
<p>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 <ahref="http://www.birdhouse.org/beos/bible/bos/ch_scripting1.html"class="printurl">Scripting Chapter</a> (<ahref="http://www.birdhouse.org/beos/bible/bos/BeOS.scripting.PDF">PDF, 900 KiB</a>) of Scot Hacker's BeOS Bible.</p>
<p>Haiku used to have scripts for booting and shutting down. Today it uses the <ahref="https://dev.haiku-os.org/wiki/LaunchDaemon">launch_daemon</a> 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.</p>
<p><spanclass="path">/boot/home/config/settings/boot/UserBootscript</span> 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:</p>
<p>Remember to end a command with an "<tt>&</tt>" 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).</p>
<p>A simple alternative to the above for launching applications at boot up is to put links to them in the <spanclass="path">/boot/home/config/settings/boot/launch</span> directory. This can be done simply by right-clicking on the application you wish to have started automatically, going to <spanclass="menu">Create Link</span> and then <ahref="tracker.html#navigating">navigating</a> to the above directory.</p>
<p><spanclass="path">/boot/home/config/settings/boot/UserShutdownScript</span> will be executed as the first step in the shutdown process. If the script returns a non-zero exit status, the shutdown is aborted.</p>
<p><spanclass="path">/boot/home/config/settings/boot/UserShutdownFinishScript</span> 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.</p>