
C H A P T E R 1 5
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
245
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
#
symbol;
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
#
symbol at the start of the line, or the shell will try to run the com-
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,
do
, is indented by typing four spaces at the start; this helps visu-
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
date
command and enter it into a variable called
filename
. The
`
symbol, known as a
backtick
,
tells the shell to execute the
date
command; without these symbols, found at either end of
the command, the shell would ignore the instruction and treat it as just a string of text.
The
date
command, as you may have guessed, allows you to find out what the current date and
time is on the system. Following the
+
symbol is a series of instructions on how the date should
be printed:
%Y
gives the year in four-digit form,
%m
the month in two-digit form,
%d
the day in
two-digit form, and
%H
,
%M
and
%S
give the time in 24-hour format hours, minutes and seconds.
Содержание A
Страница 1: ......
Страница 2: ......
Страница 3: ...Raspberry Pi User Guide 2nd Edition...
Страница 4: ......
Страница 5: ...Raspberry Pi User Guide 2nd Edition Eben Upton and Gareth Halfacree...
Страница 10: ......
Страница 26: ...R A S P B E R R Y P I U S E R G U I D E S E C O N D E D I T I O N 10...
Страница 28: ......
Страница 29: ...Chapter 1 Meet the Raspberry Pi...
Страница 37: ...Chapter 2 Getting Started with the Raspberry Pi...
Страница 56: ......
Страница 57: ...Chapter 3 Linux System Administration...
Страница 79: ...Chapter 4 Troubleshooting...
Страница 89: ...Chapter 5 Network Configuration...
Страница 109: ...Chapter 6 The Raspberry Pi Software Configuration Tool...
Страница 122: ......
Страница 123: ...Chapter 7 Advanced Raspberry Pi Configuration...
Страница 140: ......
Страница 141: ...Chapter 8 The Pi as a Home Theatre PC...
Страница 151: ...Chapter 9 The Pi as a Productivity Machine...
Страница 159: ...C H A P T E R 9 T H E P I A S A P R O D U C T I V I T Y M A C H I N E 143 Figure 9 4 Exporting a file from The Gimp...
Страница 160: ......
Страница 161: ...Chapter 10 The Pi as a Web Server...
Страница 171: ...Part III Programming with the Raspberry Pi Chapter 11 An Introduction to Scratch Chapter 12 An Introduction to Python...
Страница 172: ......
Страница 173: ...Chapter 11 An Introduction to Scratch...
Страница 189: ...Chapter 12 An Introduction to Python...
Страница 216: ......
Страница 218: ......
Страница 219: ...Chapter 13 Learning to Hack Hardware...
Страница 234: ......
Страница 235: ...Chapter 14 The GPIO Port...
Страница 249: ...Chapter 15 The Raspberry Pi Camera Module...
Страница 265: ...Chapter 16 Add on Boards...
Страница 279: ...Part V Appendixes Appendix A Python Recipes Appendix B Camera Module Quick Reference Appendix C HDMI Display Modes...
Страница 280: ......
Страница 281: ...Appendix A Python Recipes...
Страница 287: ...Appendix B Raspberry Pi Camera Module Quick Reference...
Страница 293: ...Appendix C HDMI Display Modes...