2.3 Variables of mediums
Variables of mediums contains values that are available for run programs during whole work session. Moreover these variables controls some program actions. For example utility chfn runs text editor that is situated in variable of medium EDITOR and variable TERM informs interpreter how it should format text for correct displaying on the screen. Variable BLOCKSIZE controls format of output numbers by utilities du and df: kilobytes, semikilobytes, etc. Program is not required to be initial command interpreter to contact variables of medium- every program has access to them same as program that installed them.
Variables of medium list can be viewed with help of command printenv:
# printenv
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/contrib/bin:/usr/XllR6/bin:.
MAIL=/var/mail/frank
BLOCKSIZE=lk
FTP_PASSIVE_MODE=YES
USER=frank
LOGNAME=frank
HOME=/home/frank
SHELL=/bin/tcsh
SSH_CLIENT=192.168.173.230 50095 22
SSH_TTY=/dev/ttyp0
TERM=vt100
HOSTTYPE=FreeBSD
VENDOR=intel
OSTYPE=FreeBSD
MACHTYPE=i386
SHLVL=1
PWD=/home/frank
GROUP=users
HOST=stripes.somewhere.com
REMOTEHOST=192.168.173.230
PATHSET=true
EDITOR=vi
Visual=pico
To set up variable COLOR with value gold in csh next command is use:
# setenv COLOR gold
Note that variable of medium must have value. It can not be equal to null or not defined at all.
2.4 Variables of command interpreter
There exist another set of variables that are available during work session. These variables of command interpreter are used only during current session and does not connected with other processes. They are available only for Interpreter process. In terms of programming Variables of interpreter are local and variables of medium- global, that are inherited by all programs.
Variables за interpreter in csh should belong to lower register. It can be watched through with help of command set. Setting of interpreter variables in csh is made also with help of command set. In csh interpreter variable can be defined without assigning of value:
# set history 100
# set noclobber
With help of unset variable can be deleated:
# unset autologout
2.5 Interpreter initialization files It's time to discuss how the interpreter is configured. It allows you to create aliases to simplify the commands, automatically run certain programs when you log on, set variables of medium, etc. For these tasks the initialization and configuration files that exist at the global and user levels correspond. In csh such files are used to configure .cshrc, .login and .logout. The first file, which is drawn by csh when you start is configuration system-level file /etc/csh/.cshrc immediately followed by an appeal to /etc/csh.login. Note that on FreeBSD, there exist both files, but their contents are commented out (see Listing 1). Listing 1 global file /etc/csh.cshrc and /etc/csh.login.
#cat /etc/csh.cshrc
# $FreeBSD: src/etc/csh. cshrc, v 1.3 1999/08/27 23:23:40 peter Exp $
System-level file .cshrc for csh(l) .
cat /etc/csh.login
# $FreeBSD: src/etc/csh. login, v 1.19.2.1 2000/07/31 20:13:26 rwatson AExp $
System-level file .login for csh(l).
setenv BLOCKSIZE К
to set languages and code pages refer to
login.conf(5), and to options charset and lang.
Full locale-page is situated in s /usr/share/locale/*
Reading of system messages
msgs –f
Enabling of therminal messages
mesg v
Listing shows that these files do not execute any function, but they can be used. Any change made to these files, for example, the inclusion of terminal messages, is a global and canceled only if the user configuration files corresponding option is set differently. The configuration files are similar to the system user, but addressing to them is performed a little later. These files are situated in initial user catalog: .cshrc and .login.
File .cshrc (its source is /usr/share/skel/dot.cshrc) by default performs setting of medium of command interpreter. It creates several alias:
alias h history 25
alias j jobs -1
alias la ls –a
alias lf ls –FA
alias ll ls –lA
set paths of program searching:
set path=(/sbin /bin /usr/sbin /usr/bin /uar/games /usr/local/ *sbin /usr/local/bin /usr/XHR6/bin $HOME/bin)
and also sets variables of mediums ,that control some system tasks behavior:
setenv EDITOR vi
setenv PAGER more
setenv BLOCKSIZE K
This configuration file performs some other functions. Review file. cshrc from your initial catalog on your computer. In the file. login, which is performed the next, the user places the programs that should run when it is registered in the system. For example, the default file .login (from / usr / share / skel / dot.login) includes a program fortune and a conditional statement, but this line is commented out:
# Message output during log in:
# [ -х /usr/games/fortune ] && /usr/games/fortune -s
The administrator or the user itself can specify the processes that should run when you log off. For example, it could be a script that deletes all temporary files in the directory / tmp, owned by the user. The script is enough to include in the file / etc / csh.logout, that don`t have a default executable content:
#cat /etc/csh-logout
# SFreeBSD: src/etc/csh.logout,v 1.3 1999/08/27 23:23:41 peter Exp $
#
# System-level file .logout for csh(l).
When the process exits the system also turn to file .logout in the initial user catalog, if it is there. By default, this file is not installed. All these files are executed when you start csh as the primary interpreter. However, the command interpreter can be launched and in other circumstances. For example, to run the script (if desired interpreter specified directly in the line of the script). In this case the files .login and .logout (as well as their equivalents system-level) are ignored.
2.6 Configuring of the medium of command interpreter We have already seen how to configure the medium of command interpreter using its configuration files. This is an excellent example of extending its functionality. It should be noted that there are additional opportunities, examples of which are not represented in the configuration files by default. Lets consider how they are implemented in csh. In most cases, it is built-in commands that can run either directly from a command line or in a configuration file interpreter. The interpreter can change the appearance of command line. This is achieved by setting the variable prompt: the output of any command can be used by entering it in the reverse apostrophe, as is done for example in scripts in Perl. In addition, you can display the variable containing “the number "command in history. It uses the symbol ! . Below is a fairly complex example, which used many of the properties, including the use of sed (stream editor - word processor that handles blocks of text in non-interactive mode) to reduce the host name to its first element:
# set promt =”{ `whoami `@`hostname | sed `s/\..*//’`:!} “
{ root@www:23}
At the command line, it is convenient to display the directory in which currently resides user, using the result of the command pwd:
# set promt=”{ `pwd`:!} “
{ root:24}
Setting the search path commands in csh also involves assigning value to a variable environment. To an array of values enclosed in brackets, you can not add value "on the way." You need to add a new element to a string, and then restart the command set, which is why it is best to configure the way in one of the configuration script, and not directly from the command line. The syntax is a bracketed list of paths separated by spaces:
set path = (/sbin /usr/sbin /bin /usr/bin /usr/local/bin /usr/ contrib/bin /usr/XHR6/bin /usr/local/sbin /usr/games /usr/local/ mystuff)
Another useful tool is the built-in stty. It allows you to override the code table of symbols. This is required in situations where a terminal program sends to other programs unexpected symbols, such as confusion between delete and backspace or newline symbols. You must first view the current settings:
# stty –a
Speed 38400 baud; 60 rows; 80 columns;
1flags: icanon isig iexten echo echoe -echok- echoke -echonl echoctl -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo -extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel -ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow -dtrflow -mdmbuf
cchars: discard = A0; dsusp = AY; eof = AD; eol =<undef>;
eol2=<undef>; erase= ^?;intr= ^?C; kill= ^U;
lnext ^V; min= 1; quit= ^\;reprint = ^R;
start= ^Q; status= ^T;stop= ^S; susp= ^Z;
time = 0; werase = ^W;
Now if you want to set symbol erase as ^H,you should use command:
# stty erase ^H
In addition, you can enable watch mode when the system informs about the users registered in it, and used pseudotherminals. This is achieved by a sequence of commands:
set watch= (1 any any)
set who="%n has %a %1 from %M."
Finally, if the setting of variables was performed by editing the configuration scripts do not need to go out and re-register it for the settings to take effect, enough to reread the configuration of built-in command rehash.
