Hardware Reference
In-Depth Information
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 . he ` 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.
he 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.
Search WWH ::




Custom Search