Книга: Fedora™ Unleashed, 2008 edition
Using Single Quotes to Maintain Unexpanded Variables
Using Single Quotes to Maintain Unexpanded Variables
You can surround a string with single quotes ('
) to stop the shell from expanding variables and interpreting special characters. When used for the latter purpose, the single quote is an escape character, similar to the backslash, which you learn about in the next section. Here, you learn how to use the single quote to avoid expanding a variable in a shell script. An unexpanded variable maintains its original form in the output.
In the following examples, the double quotes in the preceding examples have been changed to single quotes:
var='test string'
newvar='Value of var is $var'
echo $newvar
If you execute a shell program containing these three lines, you get the following result:
Value of var is $var
As you can see, the variable var
maintains its original format in the results, rather than having been expanded.
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces
- Using the Backslash As an Escape Character
- Using the Backtick to Replace a String with Output
- 6. Variables
- Caveats using NAT
- Data Binding Using the GridView Control
- Using the kill Command to Control Processes
- Installing Using a Network
- Using X
- Using a Display Manager
- Starting X from the Console by Using startx
- Using Fedora's switchdesk Client