forked from henrythemes/jekyll-bootstrap-theme
-
Notifications
You must be signed in to change notification settings - Fork 33
/
unix8.html
153 lines (143 loc) · 8.39 KB
/
unix8.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>UNIX Tutorial Eight</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Copyright" content="Michael Stonebank, 1995-2003" />
<link href="unixtut2.css" rel="stylesheet" type="text/css" />
<link href="unixtut2-print.css" rel="stylesheet" type="text/css" media="print" />
</head>
<body>
<div id="container">
<h2>A copy from <a href="http://www.ee.surrey.ac.uk/Teaching/Unix/"><font color="lightgrey">UNIX Tutorial for Beginners</font></a> with modified paths<br>Please use <a href="https://scilifelab.github.io/courses/ngsintro/common/emu/"><font color="lightgrey">this terminal emulator</font></a> when doing the exercises!</h2>
<h1>UNIX Tutorial Eight </h1>
<h2>8.1 UNIX Variables</h2>
<p>Variables are a way of passing information from the shell to programs when
you run them. Programs look "in the environment" for particular variables
and if they are found will use the values stored. Some are set by the system,
others by you, yet others by the shell, or any program that loads another program.
</p>
<p>Standard UNIX variables are split into two categories, environment variables
and shell variables. In broad terms, shell variables apply only to the current
instance of the shell and are used to set short-term working conditions; environment
variables have a farther reaching significance, and those set at login are valid
for the duration of the session. By convention, environment variables have UPPER
CASE and shell variables have lower case names. </p>
<h2>8.2 Environment Variables</h2>
<p>An example of an environment variable is the OSTYPE variable. The value of
this is the current operating system you are using. Type </p>
<p class="cli">% echo $OSTYPE </p>
<p>More examples of environment variables are </p>
<ul>
<li> USER (your login name)</li>
<li> HOME (the path name of your home directory)</li>
<li> HOST (the name of the computer you are using)</li>
<li> ARCH (the architecture of the computers processor)</li>
<li> DISPLAY (the name of the computer screen to display X windows)</li>
<li> PRINTER (the default printer to send print jobs)</li>
<li> PATH (the directories the shell should search to find a command)</li>
</ul>
<h3>Finding out the current values of these variables.</h3>
<p>ENVIRONMENT variables are set using the <span class="command">setenv</span> command, displayed
using the <span class="command">printenv</span> or <span class="command">env</span> commands, and unset using
the <span class="command">unsetenv</span> command. </p>
<p>To show all values of these variables, type</p>
<p class="cli">% printenv | less</p>
<h2>8.3 Shell Variables</h2>
<p>An example of a shell variable is the history variable. The value of this is
how many shell commands to save, allow the user to scroll back through all the
commands they have previously entered. Type</p>
<p class="command">% echo $history</p>
<p>More examples of shell variables are </p>
<ul>
<li>cwd (your current working directory)
</li>
<li> home (the path name of your home directory)
</li>
<li> path (the directories the shell should search to find a command)
</li>
<li> prompt (the text string used to prompt for interactive commands shell your
login shell)
</li>
</ul>
<h3>Finding out the current values of these variables.</h3>
<p>SHELL variables are both set and displayed using the <span class="command">set</span> command.
They can be unset by using the unset command. </p>
<p>To show all values of these variables, type</p>
<p class="cli">% set | less</p>
<h3>So what is the difference between PATH and path ?</h3>
<p>In general, environment and shell variables that have the same name (apart
from the case) are distinct and independent, except for possibly having the
same initial values. There are, however, exceptions. </p>
<p>Each time the shell variables home, user and term are changed, the corresponding
environment variables HOME, USER and TERM receive the same values. However,
altering the environment variables has no effect on the corresponding shell
variables. </p>
<p>PATH and path specify directories to search for commands and programs. Both
variables always represent the same directory list, and altering either automatically
causes the other to be changed. </p>
<h2>8.4 Using and setting variables</h2>
<p>Each time you login to a UNIX host, the system looks in your home directory
for initialisation files. Information in these files is used to set up your
working environment. The C and TC shells uses two files called .login and .cshrc
(note that both file names begin with a dot).</p>
<p>At login the C shell first reads <strong>.cshrc</strong> followed by <strong>.login</strong></p>
<p><strong>.login</strong> is to set conditions which will apply to the whole
session and to perform actions that are relevant only at login. </p>
<p><strong>.cshrc</strong> is used to set conditions and perform actions specific
to the shell and to each invocation of it.</p>
<p>The guidelines are to set ENVIRONMENT variables in the <strong>.login</strong>
file and SHELL variables in the <strong>.cshrc</strong> file. </p>
<p class="hint"><strong>WARNING:</strong> NEVER put commands that run graphical
displays (e.g. a web browser) in your .cshrc or .login file. </p>
<h2>8.5 Setting shell variables in the .cshrc file</h2>
<p>For example, to change the number of shell commands saved in the history list,
you need to set the shell variable history. It is set to 100 by default, but
you can increase this if you wish.</p>
<p class="cli">% set history = 200</p>
<p>Check this has worked by typing</p>
<p class="cli">% echo $history</p>
<p>However, this has only set the variable for the lifetime of the current shell.
If you open a new xterm window, it will only have the default history value
set. To PERMANENTLY set the value of history, you will need to add the set command
to the .cshrc file.</p>
<p>First open the <strong>.cshrc</strong> file in a text editor. An easy, user-friendly
editor to use is nedit.</p>
<p class="cli">% nedit ~/.cshrc</p>
<p>Add the following line AFTER the list of other commands.</p>
<p class="sourcecode"> set history = 200</p>
<p>Save the file and force the shell to reread its .cshrc file buy using the shell
source command.</p>
<p class="cli">% source .cshrc</p>
<p>Check this has worked by typing</p>
<p class="cli">% echo $history</p>
<h2>8.6 Setting the path</h2>
<p>When you type a command, your path (or PATH) variable defines in which directories
the shell will look to find the command you typed. If the system returns a message
saying "command: Command not found", this indicates that either the
command doesn't exist at all on the system or it is simply not in your path.
</p>
<p>For example, to run units, you either need to directly specify the units path
(<strong>~/units174/bin/units</strong>), or you need to have the directory <strong>~/units174/bin</strong>
in your path. </p>
<p>You can add it to the end of your existing path (the <strong>$path</strong>
represents this) by issuing the command: </p>
<p class="cli"> % set path = ($path ~/units174/bin)</p>
<p>Test that this worked by trying to run units in any directory other that where
units is actually located. </p>
<p class="cli">% cd<br />
%
units</p>
<p>To add this path PERMANENTLY, add the following line to your .cshrc AFTER the
list of other commands.</p>
<p class="cli">set path = ($path ~/units174/bin)</p>
<p align="center" class="navbar"><a href="unix7.html"><img src="media/left.gif" alt="Back" width="37" height="39" border="0" /></a>
<a href="index.html"><img src="media/home.gif" alt="Home" width="81" height="39" border="0" /></a></p>
<p align="center"><script type="text/javascript"><!--
amazon_ad_tag = "unixtutorialf-20"; amazon_ad_width = "728"; amazon_ad_height = "90"; amazon_ad_logo = "hide"; amazon_ad_link_target = "new"; amazon_ad_price = "retail"; amazon_color_border = "E9ECF5"; amazon_color_link = "0000FF"; amazon_color_logo = "093697"; amazon_ad_categories = "abcdefg";//--></script>
<script type="text/javascript" src="http://www.assoc-amazon.com/s/ads.js"></script></p>
<p class="date">[email protected] October 2001 </p>
</div>
</body>
</html>