麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 系統 > Debian > 正文

Debian Environment Variables

2024-06-28 13:19:03
字體:
來源:轉載
供稿:網友
Debian Environment Variables

原文:EnvironmentVariables


General

Environment variables are named strings available to all applications. Variables are used to adapt each application's behavior to the environment it is running in. You might define paths for files, language options, and so on. You can see each application's manual to see what variables are used by that application.

That said, there are several standard variables in linux environments:

  • PATH = Colon separated list of directories to search for binaries.
  • HOME = Current user's home directory.
  • USER = Current logged in user's name.
  • SHELL = The current shell.
  • PS1 = Defines shell's command PRompt.
  • EDITOR = defines the user's preferred text editor.
  • (please feel free to add more)

To see your currently defined variables, open up your terminal and type the commandenv

Variables are defined with name-value pairs: "NAME = any string as value". The variable name is usually in capital letters. Anything that follows the equal-sign is considered the variable's value until the terminating line feed character. Any whitespace around the equal-sign is ignored. Variables can be defined ad hoc in a terminal by writing the appropriate command. In Bash this would be 'export MYVAL=Hello world'. In this case the variable stays defined until the end of the terminal session.

When working in shells or shell scripts: If you do not want to over-write the previous value of the variable, include the variable name into the new definition. E.g. in Bash:exportPATH=$PATH:~/bin. This example shows how to append the bin directory in the user's home directory onto the PATH environment variable.

In most cases it is most convenient to store these variables in a configuration file that is read during system boot and user login so that they are available automatically. Unfortunately this not always as easy as it sounds. Why? For a couple of reasons:

  1. Environment variables are inherited; i.e., the parent program sets the environment for the child process. You need to configure the parent's settings so that it passes it on for all its children.
  2. Various shells and window managers are the parent programs we are looking for but each of them reads a different configuration file (dot file) when it starts.

So, with this knowledge we understand that we need to consider both the starting order of system processes and the configuration files they read when they are started. See theDotFilespage, or read on ...

Lets get to it! There are two ways you can run your Linux box: from text console or graphical user interface.

Using text console

Boot process in regards to environment variable definition when a text console (also called login shell) is used.

  1. At the end of boot the mother of all processesinitis started. init's environment, including PATH, is defined in its source code and cannot be changed at run time.

  2. init runs the start-up scripts from/etc/init.ddepending on the run level set in /etc/inittab. Since init's environment is very bare, the scripts define their required environment variables within themselves.

  3. init starts the text login process that waits for the user to log in. When the user logs in, the login process checks/etc/passwdto see what shell should be started for this particular user.

  4. The shell starts and reads its shell-specific configuration files.
    1. Bash first reads/etc/profileto get values that are defined for all users. After reading that file, it looks for~/.bash_profile',~/.bash_login', and `~/.profile', in that order, and reads and executes commands from the first of these files that exists and is readable.b. (please fill in other shells as well)

Now the environment variables are ready to be used by the applications you start from the terminal.

Using graphical UI

Boot process in regards of environment variable definition when graphical login is used. (Information here is Gnome / GDM specific)

  1. At the end of booting, the mother of all processes --init-- is started.

  2. init runs the start-up scripts from/etc/init.ddepending on the run level set in /etc/inittab. Since init's environment is very bare, the scripts define required environment variables within themselves.

  3. Init starts the GDM display manager, which in turn will start the graphical login.
  4. When the user successfully logs in, GDM starts xsession, which reads the file/etc/gdm/Xsessionand with it the environment variables for the user's session. The default version of theXsessionfile first reads/etc/profilefor global settings and then~/.profileto add the user's individual settings.

Now the environment variables are set and used when programs are run in this session.

Quick guide

For the hasty who just need to get the system running, here is what you can do:

  • Put all global definitions, i.e. ones affecting all users into/etc/profile.

  • Insert all personal definitions into~/.profile

  • Create or edit file~/.bash_profileand include commands:

     if [ -f ~/.profile ]; then     . ~/.profile fi

Notes and exceptions

startx from terminal

If you start X Window (the GUI) from a text console, your environment variables are already defined as explained above. However, the window manager may read the same files again (see below). This is usually not a problem, but you may get unexpected results, such as PATH having all entries listed twice.

Shell cascading

If you start another shell within the login shell (yes it is possible), the second one is a non-login shell. It will not read named start-up files but searches non-login start-up script from user's home directory instead. With Bash it is called~/.bashrc. To avoid specifying same values in two places usually the login-shell start-up script~/.bash_profileincludes the~/.bashrcat the end of its execution. To implement include following into your~/.bash_profile:

if [ -f ~/.bashrc ]; then   . ~/.bashrc;fi

terminal windows in X

If you start terminal / console window in graphical desktop environment it will be non-login terminal and it will read only the user's non-login start-up script. For Bash this is~/.bashrc.

Using su

Thesucommand is used to become another user during a login session. It is commonly used to get root permissions temporarily from normal session.sucommand resets your PATH environment value to one defined in/etc/login.defsby ENV_PATH and ENV_SUPATH variables. Please note that using Gnome helpergksufrom Gnome panel by default usessuinternally (i.e. you will "lose" your PATH if you do not configure it in login.defs).


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 麻豆一区二区99久久久久 | 亚洲人成综合第一网 | 黄色小视频免费在线观看 | 成人精品 | 精品三区视频 | 欧美性生活久久 | 国产一级毛片高清视频 | 一级黄色影片在线观看 | 免看黄大片aa | 色就操 | 欧美精品v国产精品v日韩精品 | 香蕉黄色网 | 亚洲欧美天堂 | 成人在线免费观看小视频 | av在线免费看网站 | 成人在线视频在线观看 | 特级黄aaaaaaaaa毛片 | 韩国一级免费视频 | 九九热国产视频 | 久久亚洲精品国产一区 | 欧美日本一区二区 | 久久综合久久综合久久综合 | 国产在线观看一区二区三区 | 在线亚洲欧美 | 国产成人精品网站 | 欧美自拍 | 毛片毛片| 久久情爱网 | 久久久成人免费视频 | 92看片淫黄大片一级 | 一区免费| 一区二区三区视频在线观看 | 国产精品久久久久久久久久妇女 | 久久午夜国产 | 在线观看麻豆 | 久久亚洲精品久久国产一区二区 | 日本高清电影在线播放 | 粉嫩粉嫩一区二区三区在线播放 | 中文字幕在线亚洲精品 | 久久精品视频首页 | 国产精品美女久久久久久不卡 |