28.09.2018 Views

Linux Dummies 9th

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

326<br />

Part IV: Junior Administrator Boot Camp<br />

Take a look at a different kind of string that the shell interprets differently: an<br />

interpolated string. An interpolated value is one in which the shell interprets<br />

special characters before processing the value. Rather than using single<br />

quotes, this time you use the same example with double quotes:<br />

echo “Hello, my name is $USER”<br />

Notice what the output is this time:<br />

Hello, my name is rich<br />

Instead of displaying the exact text you provided, the shell replaces the variable<br />

name, designated with a dollar sign, with the actual value stored in that<br />

variable.<br />

Why did you use single quotes in the first example but double quotes with the<br />

second one? The items with the backslashes (\) are interpreted one way or<br />

another. However, if you use double quotes, they’re interpreted only once, so<br />

the item that lists what directory you’re in changes only the first time. If you<br />

use single quotes, the variables are interpreted every time you do something.<br />

If you’re going to play around with environment variables, start by using<br />

the methods we discuss in this section. After you’re comfortable with any<br />

changes you have made, you can make your changes permanent by opening<br />

the ~/.bashrc file and adding the same text there. The next time you log in,<br />

the changes go into effect. You can make changes for all your users’ profiles<br />

in /etc/profile as well.<br />

If you experiment heavily with these files, create a separate user account so<br />

that you can do whatever you want without messing up your own login. This<br />

advice especially goes for /etc/profile. You can damage everyone’s logins<br />

with this one! To create a separate /etc/profile, you can make a backup<br />

by typing cp /etc/profile /etc/profile.original. Then edit /etc/<br />

profile all you like, knowing that you can always delete it with the rm command<br />

and use the mv command to rename /etc/profile.original to<br />

/etc/profile.<br />

To create an environment variable from scratch, you typically name it with<br />

all capital letters and then you have to export it — like this, for example:<br />

CUSTOMVAR=”new variable”<br />

export CUSTOMVAR<br />

Don’t be too discouraged if you don’t understand all this variable stuff right<br />

now. As you become more proficient with <strong>Linux</strong>, you should explore shell<br />

scripting. Shell scripting is the art of creating computer programs with just<br />

the shell. Most <strong>Linux</strong> and UNIX administrators speak shell-script language as<br />

easily as you and I speak our native tongues.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!