C H A P T E R 1 5 - Raspberry Pi A User Manual

Hide thumbs Also See for Raspberry Pi A:
Table of Contents

Advertisement

C H A P T E R 1 5

Although other shells are available, Bash is the default for most modern Linux distributions
and offers a good mix of guaranteed compatibility and advanced features. Everything after
this line will be run by the operating system as a command just as though you had typed it at
the terminal yourself. The exception is comment lines, which are preceded by a
these lines contain notes that help you remember why the script is written in a particular
way, or how to use the script. It's good practice to include comment lines in your shell scripts,
although the script will run fine without them.
So that you know what the script is supposed to do when you find the file a few months from
now, make the next line a comment explaining the script's purpose:
# Captures time-lapse images using the raspistill application
Remember to put the
#
ment as a command.
Next is to set up a loop that will ensure the script continues to run after the first photograph
has been taken. Enter the following two lines to start the loop:
while true
do
Note that the second line,
ally illustrate that the code that appears below is part of the loop. Unlike Python, which
requires indentation, shell scripts can be written without any code being indented—but it
makes the code significantly harder to read and understand. Like comments, indentation is
an optional but highly recommended step.
Next, set up the filename that will be saved by entering the following line:
filename=`date +%Y%m%dT%H%M%S`.jpg
This is a somewhat complex instruction that tells the shell to take the output of the
command and enter it into a variable called
tells the shell to execute the
the command, the shell would ignore the instruction and treat it as just a string of text.
The
command, as you may have guessed, allows you to find out what the current date and
date
time is on the system. Following the
be printed:
gives the year in four-digit form,
%Y
two-digit form, and
,
%H
%M
T H E R A S P B E R R Y P I C A M E R A M O D U L E
symbol at the start of the line, or the shell will try to run the com-
, is indented by typing four spaces at the start; this helps visu-
do
filename
command; without these symbols, found at either end of
date
symbol is a series of instructions on how the date should
+
%m
and
give the time in 24-hour format hours, minutes and seconds.
%S
. The
symbol, known as a backtick,
`
the month in two-digit form,
symbol;
#
date
the day in
%d
245

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Raspberry pi b

Table of Contents