Книга: Fedora™ Unleashed, 2008 edition

Using the Backslash As an Escape Character

Using the Backslash As an Escape Character

As you learned earlier, the backslash () serves as an escape character that stops the shell from interpreting the succeeding character as a special character. Imagine that you want to assign a value of $test to a variable called var. If you use the following command, the shell reads the special character $ and interprets $test as the value of the variable test. No value has been assigned to test; a null value is stored in var as follows:

Command Environment
var=$test bash
set var=$test tcsh

Unfortunately, this assignment might work for bash, but it returns an error of undefined variable if you use it with tcsh. Use the following commands to correctly store $test in var:

Command Environment
var=$test bash
set var = $test tcsh

The backslash before the dollar sign ($) signals the shell to interpret the $ as any other ordinary character and not to associate any special meaning to it. You could also use single quotes (') around the $test variable to get the same result.

Оглавление книги


Генерация: 1.272. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз