[Contents] [Prev. Chapter] [Next Section] [Next Chapter] [Index] [Help]

3    Migrating Your ULTRIX User Environment to a DIGITAL UNIX System

This chapter describes how to set up your DIGITAL UNIX user environment so that it is similar to your ULTRIX user environment. This chapter also describes how to port shell scripts from an ULTRIX system to a DIGITAL UNIX system.


[Contents] [Prev. Chapter] [Next Section] [Next Chapter] [Index] [Help]

3.1    Setting Environment Variables

In most cases, you can set environment variables on your DIGITAL UNIX system the same as you set them on your ULTRIX system. You might need to set the following environment variables differently on a DIGITAL UNIX system:

This section describes how you set these environment variables. Note that the CSHEDIT environment variable is not supported on the DIGITAL UNIX system. To enable command-line editing, enter the following command:

% set editmode {emacs|vi}

You can include this command in your .login file to have the editmode variable set each time you log in or in your .cshrc file to set the variable in all subshells.


[Contents] [Prev. Chapter] [Prev. Section] [Next Section] [Next Chapter] [Index] [Help]

3.1.1    Setting the C Shell filec and PATH Environment Variables

The DIGITAL UNIX system C shell contains most features of the ULTRIX C shell. One difference between the two shells is that the ULTRIX C shell includes file name completion by default. On DIGITAL UNIX systems, you must set the filec environment variable to enable file name completion.

To set the filec environment variable, enter the following command:

% set filec

You can include this command in your .login file to have the filec variable set each time you log in or in your .cshrc file to set the variable in all subshells. Once you set the variable, you can press the Escape key to request that the shell complete file names on the command line.

On DIGITAL UNIX systems, the default search path for the csh shell is .:/usr/bin. On ULTRIX systems, the default search path is .:/usr/bin:/bin. On the DIGITAL UNIX system, the /usr/ucb directory is a link to the /usr/bin directory. For information about the DIGITAL UNIX C shell, see csh(1).


[Contents] [Prev. Chapter] [Prev. Section] [Next Section] [Next Chapter] [Index] [Help]

3.1.2    Setting the Bourne Shell PATH Environment Variable

On DIGITAL UNIX systems, the default search path for the sh shell is :/usr/bin. On ULTRIX systems, the default search path is :/usr/bin:/bin. On the DIGITAL UNIX system, the /bin directory is a link to /usr/bin, so there is no need to add /bin to your path. However, there are commands in /usr/sbin that you might want to access. To enable the shell to access commands in /usr/sbin, add that directory to the sh search path. The following example shows the line to include in your .profile file to add the /bin directory to the default search path:

PATH=:/usr/bin:/usr/sbin; export PATH

Including this command in your .profile file adds the /usr/sbin directory to the default sh search path each time you log in to the system.


[Contents] [Prev. Chapter] [Prev. Section] [Next Section] [Next Chapter] [Index] [Help]

3.1.3    Setting International Environment Variables

The DIGITAL UNIX system has environment variables that control some aspects of how you interact with programs. The environment variables control how international programs display messages, accept input, and display data. International programs use DIGITAL UNIX features to display messages in your native language, collate strings as you expect, format monetary and numeric data as you expect, and so on. The following sections describe how to set these environment variables.


[Contents] [Prev. Chapter] [Prev. Section] [Next Section] [Next Chapter] [Index] [Help]

3.1.3.1    Setting the Environment Variable for Messages

To display a message in your native language, a program reads the message from a message catalog. By default, your program searches the /usr/lib/nls/msg/%L /%N path for message catalogs. In the preceding pathname, %L represents the locale name specified by the LANG environment variable, and %N represents the name of the message catalog, which is usually similar to program_name.cat.

If the message catalog your program needs is not stored in one of the default directories, you must set the NLSPATH environment variable, as you did on ULTRIX systems. The NLSPATH environment variable tells the program where to find the message catalogs.


[Contents] [Prev. Chapter] [Prev. Section] [Next Section] [Next Chapter] [Index] [Help]

3.1.3.2    Setting the Environment Variables for Data Handling

You can set a number of environment variables that control how programs accept input, display data, and manipulate data. The international environment variables on a DIGITAL UNIX system are LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_NUMERIC, LC_MONETARY, LC_TIME, and LC_MESSAGES. For a description of these environment variables, see Section 6.10.2.1.

To define these international environment variables, you specify a string, called the locale name, that tells the system what language, territory, and codeset to use in your environment. You may also be able to specify a modifier that allows you to further refine program display and data input.

The DIGITAL UNIX system uses a naming convention for locales different from the ULTRIX system. On ULTRIX systems, the language specifier is three characters long and uppercase. On DIGITAL UNIX systems, the language specifier is two characters long and lowercase. In addition, the format of the codeset names differ between the ULTRIX and DIGITAL UNIX systems. For example, to choose an environment that supports French as it is spoken in France, enter the following command on a DIGITAL UNIX system:

% setenv LANG fr_FR.ISO8859-1

On ULTRIX systems, international environment variables have little effect on the commands on the system. For example, setting the LC_TIME variable to a French locale name does not cause the date command to display dates as you expect them to be displayed in France. However, on DIGITAL UNIX systems, the setting of the LC_TIME variable does affect the operation of the date command, as well as other commands.

The DIGITAL UNIX system supports more locales than the ULTRIX system. However, the ULTRIX ISO 646 and DEC Multinational character set codesets are not supported on DIGITAL UNIX systems. Therefore, the following locales are unavailable on DIGITAL UNIX systems:

On DIGITAL UNIX systems, locales are installed in the /usr/lib/nls/loc directory. For a list of available locales, see the Technical Overview.


[Contents] [Prev. Chapter] [Prev. Section] [Next Section] [Next Chapter] [Index] [Help]

3.2    Migrating Shell Scripts

In most cases, your shell scripts will port from ULTRIX to DIGITAL UNIX with few modifications. You might need to modify your shell script because of differences between DIGITAL UNIX and ULTRIX commands or because of differences between the shells on DIGITAL UNIX and ULTRIX systems.


[Contents] [Prev. Chapter] [Prev. Section] [Next Section] [Next Chapter] [Index] [Help]

3.2.1    Modifying Commands Used in Scripts

A number of commands are different between DIGITAL UNIX and ULTRIX systems. Most differences are in the options or arguments for a given command. Some commands operate differently on DIGITAL UNIX systems, and some ULTRIX commands are unavailable on DIGITAL UNIX systems.

For example, the DIGITAL UNIX test command works differently from the ULTRIX test command. On a DIGITAL UNIX system, the -f option makes the test command determine whether a file exists and is a regular file; that is, the file is not a directory, a character-special file, a block-special file, or a named pipe. On an ULTRIX system, the -f option makes the test command determine whether a file exists and is not a directory. Because of this difference, the test -f command can return unexpected results on a DIGITAL UNIX system. You can get the effect of the ULTRIX test -f command on a DIGITAL UNIX system by replacing the test -f command with the following command:

(test -f file) -o (test -c file) -o (test -b file) -o (test -p file)

By sequentially testing for a regular file (-f), a character-special file (-c), a block-special file (-b), or a named pipe (-p), this command tests one file to be sure it is not a directory. The command returns status in the same way as the ULTRIX test -f command.

If your scripts contain explicit path references to commands that are in different directories on the DIGITAL UNIX system, you must change these references to reflect the DIGITAL UNIX locations.

For more information about command differences that could affect porting your shell script from ULTRIX to DIGITAL UNIX, see Appendix A.


[Contents] [Prev. Chapter] [Prev. Section] [Next Section] [Next Chapter] [Index] [Help]

3.2.2    Migrating Korn Shell Scripts

The Korn shell (ksh) is the same on DIGITAL UNIX and ULTRIX systems. You need not modify your shell scripts.


[Contents] [Prev. Chapter] [Prev. Section] [Next Section] [Next Chapter] [Index] [Help]

3.2.3    Migrating C Shell Scripts

The C shell on DIGITAL UNIX systems is the same as the C shell on ULTRIX systems, with one exception. Because the C shell on DIGITAL UNIX systems does not support the hashstat built-in command, you must remove it from the ULTRIX C shell script before you move the script to a DIGITAL UNIX system. The DIGITAL UNIX system does not have an equivalent for this command.


[Contents] [Prev. Chapter] [Prev. Section] [Next Section] [Next Chapter] [Index] [Help]

3.2.4    Migrating sh Shell Scripts

The Bourne shell on DIGITAL UNIX systems is largely the same as the Bourne shell on ULTRIX systems. Some differences between the two shells do exist. The following list describes changes you should make to your ULTRIX sh scripts or your user environment to port sh scripts to a DIGITAL UNIX system:


[Contents] [Prev. Chapter] [Prev. Section] [Next Chapter] [Index] [Help]

3.2.5    Migrating sh5 Shell Scripts

The first two bytes of an executable program, called a magic number, tell the system what kind of program it is. The first line of most shell scripts is a magic number consisting of the combination of a number sign and an exclamation point (#!). This magic number tells the system to execute the rest of the line as if it were a normal shell command. Most shell scripts invoke the shell for which they are written to ensure that the script is executed by the appropriate shell. The first line of most scripts written for the ULTRIX sh5 shell is:

#! /bin/sh5

Because the DIGITAL UNIX system uses a different name for the Bourne shell, these scripts fail. You must modify the first line to invoke the sh shell on a DIGITAL UNIX system, as shown:

#! /bin/sh

If a script must run when the system is in single-user mode, specify /sbin/sh instead of /bin/sh to get the statically linked version of the shell.

One significant difference between the ULTRIX sh5 shell and the DIGITAL UNIX sh shell is in their treatment of positional parameters when a function is called. The DIGITAL UNIX sh shell sets the positional parameters to the function call's arguments as does the ULTRIX sh5 shell. However, the DIGITAL UNIX sh shell also saves the values the positional parameters held before the function was called. Upon return from the function, the shell sets the positional parameters to the saved values. The ULTRIX sh5 shell does not restore the positional parameters in this way; it leaves them set to the values they hold when the function returns. If your scripts do not rely on the ULTRIX behavior, this difference is transparent.

The most efficient way to modify the first line in a number of sh5 scripts is to write a shell script. Example 3-1 shows a shell script that changes the first line in sh5 scripts.

Example 3-1:  Shell Script to Convert sh5 Scripts into sh Scripts

#! /bin/sh
trap 'rm -f /tmp/conv$$ ; exit ' 0 1 2             [1]
for i                                              [2]
do
     sed 'ls/bin\/sh5/bin\/sh/' $i > /tmp/conv$$   [3]
     [ -f /tmp/conv$$ ] && {                       [4]
          mv /tmp/conv$$ $i                        [5]
}
done

  1. The trap command makes the shell recognize the 0, 1, or 2 signals. If the shell receives one of these signals, it removes the file /tmp/conv$$, where $$ is the process number of the current process. The shell script uses this file during its processing.

    Once the /tmp/conv$$ file is removed, the shell script exits. [Return to example]

  2. The for command starts a loop that continues as long as there are arguments on the shell script command line. Therefore, if you invoke this shell script with three arguments, the loop executes three times. The loop executes the commands between do and done. [Return to example]

  3. The sed command modifies the first line of its input. The command searches for the string bin/sh5 and replaces it with the string bin/sh. The sed command writes its output to the /tmp/conv$$ file. [Return to example]

  4. The command in brackets ( [ ] ) tests to see that the /tmp/conv$$ file exists and has a size greater than zero.

    The brackets are an alias for the /usr/bin/test command.

    The && separator specifies that the command in braces ( { } ) is executed only if the test is true. [Return to example]

  5. The mv command moves the /tmp/conv$$ file to the location of the original input file. In effect, this command writes the converted shell script over the input file. [Return to example]

The shell script in Example 3-1 modifies only the first line in its input. You cannot use it to replace any sh5 invocation commands that appear on lines other than the first line of a shell script. You must either modify those invocation commands by hand or modify this shell script so that it replaces all sh5 invocation commands.

To use the shell script in Example 3-1, use the vi editor or some other editor to create a file on your DIGITAL UNIX system that contains the script. Then, use the chmod command to set the file permissions on the script so that you can execute it. For example, if you name the script convert, enter the following chmod command:

% chmod u+x convert

Invoke the shell script by typing its name, followed by the names of sh5 scripts you want to convert. You can name as many shell scripts as you want on the command line, up to the maximum command-line length.

For example, suppose you want to convert three shell scripts: setup, modify, and remove. To convert the three shell scripts, enter the following command:

% convert setup modify remove

The convert script reads each file, one at a time, and changes its first line, if necessary. The converted shell script is stored in the same file as the input shell script; in this case, the converted shell scripts are named setup, modify, and remove.

Be sure to test the converted shell scripts for other possible incompatibilities before placing them into daily use.


[Contents] [Prev. Chapter] [Prev. Section] [Next Chapter] [Index] [Help]