Special Characters and Quotes

team bbl


Shell scripts can take advantage of the special meanings given to certain characters. Useful special characters are:

  • * Represents any string of characters in a filename. Used alone, * results in a list of all filenames in the current directory, except filenames that begin with a dot.

  • ? Represents a single character in a filename. Using file? would result in a list of filenames containing file1, file3, and file9, but not file10, file20, etc.

  • […] A substitution list that contains a set of characters to be matched. For instance, if you used file[xyz], the resulting list would include filex and filey, but not filea or fileq.

  • [!…] A substitution list that contains a set of characters to avoid. For instance, the list generated using file[xyz] would include fileb and filew, but not filex or filez.

  • $ Signals the beginning of a variable name.

You can turn off the meaning of special characters by enclosing them in quotes. Double quotes and single quotes have different effects. Double quotes turn off some special characters, but allow the substitution of variables values. Single quotes turn off all special characters, allowing no variable substitution, as shown by the following commands:

 city="San Diego" echo $city "$city" '$city' San Diego San Diego $city 

As you can see, the single quotes turn off the $ and echo the literal characters between the quotes. You can tell the shell to treat a special character as a literal by preceding it with a back slash, as follows:

 echo \$city $city 

    team bbl



    Spring Into Linux
    Spring Into Linux
    ISBN: 0131853546
    EAN: 2147483647
    Year: 2005
    Pages: 362
    Authors: Janet Valade

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net