Customizing the shell Environment of the AIX operating system

Source: Internet
Author: User
Tags aliases posix terminates

The main interface between the operating system and the outside is called the shell. The shell is the outermost layer of the operating system. The shell manages your interactions with the operating system: waiting for your input, explaining your input to the operating system, and processing the output of a wide variety of operating systems.

The shell provides a way for you to communicate with the operating system. This communication can be entered interactively (from the keyboard and can be immediately responded to) or executed in shell script (non-interactive) mode. Shell script is a string of shell and OS commands placed in a file that can be reused. Essentially, shell script is a simple combination of command-line commands into a file.

Interactive shell and non-interactive shell

The interactive mode is where the shell waits for your input and executes the commands you submit. This pattern is called interactive because the shell interacts with the user. This mode is also familiar to most users: Log in, execute some commands, and check back. When you sign back, the shell also terminates.

The shell can also run in a different mode: non-interactive mode. In this mode, the shell does not interact with you, but instead reads the commands stored in the file and executes them. When it reads the end of the file, the shell terminates.

Type of shell

There are two major types of shells in Unix

Bourne Shell (including sh, ksh, and bash)

Bourne Shell (SH)

Korn Shell (Ksh)

Bourne Again Shell (bash)

POSIX Shell (SH)

C Shell (including csh and TCSH)

C Shell (CSH)

Tenex/tops C Shell (tcsh)

Bourne Shell

The original Unix shell was written by Stephen R. Bourne in the mid 1970s at the T-Bell Lab in New Jersey, the Bourne shell. The Bourne shell is a switch-type command interpreter and command programming language. The Bourne shell can be run as either the login shell or the login Shell's Child shell (Subshell). Only the login command can invoke the Bourne shell as a login shell. At this point, the shell reads the/etc/profile file and the $home/.profile file first. /etc/profile files are custom environments for all users, $HOME/.profile files for this user-defined environment. Finally, the shell waits for your input to be read.

C Shell

Bill Joy developed the C shell at the University of California in Berkeley in the early the 1980s. It is primarily intended to make it easier for users to use interactive features and to turn the grammatical structure of the ALGOL style into a C language style. It adds features such as command history, aliases, file name substitution, job control, and more.

Korn Shell

For a long time, there were only two types of shells for people to choose from, Bourne shell for programming, and C shell for interaction. To change the situation, the Bell lab David Korn developed the Korn shell. Ksh combines all of the C Shell's interactive features and incorporates the syntax of the Bourne shell. As a result, Korn shell is popular with users. It also adds features such as mathematical calculations, process collaboration (coprocess), inline editing (editing), and more. The Korn Shell is an interactive command interpreter and command programming language. It complies with the international standard of posix--an operating system. POSIX is not an operating system, but one that targets the portability of applications-across multiple platforms at the source program level.

Bourne Again Shell (bash)

Bash is part of the GNU program to replace the Bourne shell. It is used for GNU-based systems such as Linux. Most Linux (Red Hat, Slackware, Caldera) uses bash as the default shell, and when you run SH, bash is actually called.

POSIX Shell

The POSIX shell is a variant of the Korn shell. The largest vendor currently providing POSIX shells is Hewlett-Packard. At HP-UX 11.0, the POSIX shell is/bin/sh, and BSH is/usr/old/bin/sh.

The default shell for each major operating system:

AIX is the Korn Shell.

The default for Solaris and FreeBSD is the Bourne shell.

The default for HP-UX is the POSIX shell.

Linux is the Bourne Again Shell.

"TIP"

Use of #!/usr/bin/sh

The first line of the shell script is generally #!/usr/bin/sh or #!/usr/bin/ksh, and its purpose is to indicate which shell the script is written in, and what shell the system should use to interpret the execution.

When you log in, the shell reads the previously set initialization file to set the user environment. The definition of a user environment is achieved by setting environment variables. When logging into the operating system, the shell uses two major categories of profile files to define the user environment. One is to customize the environment for all users, and the other is to define your own environment for individuals.

When you log on, the shell first executes the commands in the/etc/profile file, and then runs the commands in the/etc/environment file to set up your system environment. After the two files have been run, the system will then check to see if there is a. profile file in your home directory, and if the. porfile file exists, run it. The profile file also indicates whether there is an environment file. If there is an environment file (usually called. Env or. KSHRC) present, the system runs the file and sets up your environment variables.

/etc/profile file

The first file that the operating system uses to customize the user environment when a user logs on is/etc/profile. This file controls the system-wide default variables, such as export variables, file creation masks, terminal types, and prompt messages when new messages arrive.

The system administrator configures the Porfile file for all users, and only the system administrator can change the file.

/etc/environment file

The second file that the operating system uses when logging on is/etc/environment. The/etc/environment file contains variables for the basic environment that are configured for all processes. When a new process starts, the Exec subroutine generates an array of strings that are shaped as name=value. This array of strings is called the environment, and each defined name is called an environment variable or a shell variable. The Exec subroutine allows the entire environment to be set up once.

When you log in, the system sets environment variables for environment files before reading your own profile. Here are the variables that make up the basic environment:

Home: The user is logged in or the home full path, and the login program reads and sets it from the/etc/passwd file.

LANG: Language Environment

Nlspath: The full path of the message directory.

Locpath: The full path of the International Language Support system table

PATH: Directory to search for commands

TZ: Time zone information, IBM must now use taist--Taipei time zone

"Note" cannot contain commands in the/etc/environment file

. profile file

The third file that the operating system uses to log on is the. Profile file: The profile file is located in the user's home directory, which allows the user to customize their own personal work environment.

After the login program adds the logname and HOME variables to the environment, the commands in the $HOME/.profile file are executed, and the. porfile file contains your personal settings that omit conflicting variables from the/etc/profile file.

General use. Profile to control the following default values:

Open the shell, command-line prompt, keyboard sound.

. env file

If you have the following in the. profile file: env= $HOME/.env, the fourth file that the operating system uses when the user logs on is an. env file. env file allows users to customize their own personal work environment. Your personal environment variables contained in the file will ignore the conflicting variables in the/etc/environment file.

"Note" The/etc/profile,/etc/environment and. Profile files are run only once at logon. However, the. env file is executed every time a new shell or a window is opened.

"TIP" $HOME/.env file name can be arbitrary, but in $home/.profile to have the corresponding declaration: Export env= $HOME/. NewName

The "TIP" $HOME/.env file is executed whenever a child shell is opened, so you can define aliases that can also be used in the child shells opened in VI.

"Note" In these four custom environment files, only variables can be assigned to a variable in the/etc/enviroment file, while the other three files may use statements.

Customizing the shell Environment of the AIX operating system

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.