Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1
[a-z] Specifies all characters  a   through z

[a,z]   or
[az]

Specifies   characters  a   or  z

Space Acts  as  a   delimiter   between two words

Special characters are very useful when you’re creating shell scripts, but if
you inadvertently use a special character as part of a variable name or string,
your program behaves incorrectly. As you learn in later parts of this chapter,
you can use one of the special characters in a string if you precede it with an
escape character (\, or backslash) to indicate that it isn’t being used as a
special character and shouldn’t be treated as such by the program.


A few special characters deserve special note: double quotes (”),single quotes
(’), backslash (), and backtick (`), all of which are discussed in the
following sections.


Using Double Quotes to Resolve Variables in Strings with

Embedded Spaces

If a string contains embedded spaces, you can enclose the string in double
quotes (”) so that the shell interprets the whole string as one entity instead of
as more than one.


For example, if you assigned the value abc def (abc followed by one
space, followed by def) to a variable called x in a shell program as follows,
you would get an error because the shell would try to execute def as a
separate command:


Command Environment

x=abc   def pdksh   and bash

set x   =   adb deftcsh

The shell executes the string as a single command if you surround the string
in double quotes, as follows:


Command Environment

x=“abc  def” pdksh  and bash
Free download pdf