参考链接:
http://www.cyberciti.biz/faq/set-environment-variable-linux/
http://bash.cyberciti.biz/guide/Variables#Commonly_Used_Shell_Variables
列出所有系统环境变量
To see all system variables, type the following command at a console / terminal:
set
OR
env
OR
printenv
给环境变量赋值
You can modify each environmental or system variable using the export command. Set the PATH environment variable to include the directory where you installed the bin directory with perl and shell scripts:
export PATH=${PATH}:/home/vivek/bin
OR
export PATH=${PATH}:${HOME}/bin
To set the JAVA_HOME environment variable to the directory where you installed the J2SE SDK application, enter:
export PATH=${PATH}:/usr/java/jdk1.5.0_07/bin
You can set multiple paths as follows:
export ANT_HOME=/path/to/ant/dir export PATH=${PATH}:${ANT_HOME}/bin:${JAVA_HOME}/bin
How Do I Make All Settings permanent?
The ~/.bash_profile ($HOME/.bash_profile) or ~/.prfile file is executed when you login using console or remotely using ssh. Type the following command to edit ~/.bash_profile file, enter:$ vi ~/.bash_proflle
Append the $PATH settings, enter:export PATH=${PATH}:${HOME}/bin
Save and close the file.
A Note About /etc/profile File
/etc/profile contains Linux system wide environment and startup programs. It is used by all users with bash, ksh, sh shell. Usually used to set PATH variable, user limits, and other settings for user. It only runs for login shell. If you wanted to make large changes or application specific changes use /etc/profile.d/ directory as explained here andhere.
Commonly Used Shell Variables
The following variables are set by the shell:
BASH_VERSION | Holds the version of this instance of bash. | echo $BASH_VERSION |
HOSTNAME | The name of the your computer. | echo $HOSTNAME |
CDPATH | The search path for the cd command. | echo $CDPATH |
HISTFILE | The name of the file in which command history is saved. | echo $HISTFILE |
HISTFILESIZE | The maximum number of lines contained in the history file. | echo $HISTFILESIZE |
HISTSIZE | The number of commands to remember in the command history. The default value is 500. | echo $HISTSIZE |
HOME | The home directory of the current user. | echo $HOME |
IFS | The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is <space><tab><newline>. | echo $IFS |
LANG | Used to determine the locale category for any category not specifically selected with a variable starting with LC_. | echo $LANG |
PATH | The search path for commands. It is a colon-separated list of directories in which the shell looks for commands. | echo $PATH |
PS1 | Your prompt settings. | echo $PS1 |
TMOUT | The default timeout for the read builtin command. Also in an interactive shell, the value is interpreted as the number of seconds to wait for input after issuing the command. If not input provided it will logout user. | echo $TMOUT |
TERM | Your login terminal type. | echo $TERM export TERM=vt100 |
SHELL | Set path to login shell. | echo $SHELL |
DISPLAY | Set X display name | echo $DISPLAY export DISPLAY=:0.1 |
EDITOR | Set name of default text editor. | export EDITOR=/usr/bin/vim |
- Note you may add above variable (export command) to the initialization file located in the home directory of your account such as ~/.bash_profile.
显示单个环境变量的值
Use echo command to display variable value. To display the program search path, type:
echo "$PATH"
To display your prompt setting, type:
echo "$PS1"
All variable names must be prefixed with $ symbol, and the entire construct should be enclosed in quotes. Try the following example to display the value of a variable without using $ prefix:
echo "HOME"
To display the value of a variable with echo $HOME:
echo "$HOME"
You must use $ followed by variable name to print a variable's contents.
The variable name may also be enclosed in braces:
echo "${HOME}"
This is useful when the variable name is followed by a character that could be part of a variable name:
echo "${HOME}work"
Say hello to printf
The printf command is just like echo command and is available under various versions of UNIX operating systems. It is a good idea to use printf if portability is a major concern for you. The syntax is as follows:
printf "$VARIABLE_NAME\n" printf "String %s" $VARIABLE_NAME printf "Signed Decimal Number %d" $VARIABLE_NAME printf "Floating Point Number %f" $VARIABLE_NAME
To display the program search path, type:
printf "$PATH\n"
OR
printf "The path is set to %s\n" $PATH
相关推荐
本文将详细介绍 Ubuntu Linux 系统中环境变量 `PATH` 的配置方法,并对相关的配置文件进行深入解析。 #### 二、关键配置文件及作用 在 Ubuntu Linux 系统中,存在多个关键配置文件用于设置环境变量 `PATH`。以下是...
了解如何设置和管理环境变量对于任何Linux用户,尤其是开发者和系统管理员来说都是至关重要的。这篇博客将深入探讨如何在Linux中设置环境变量,并结合`Shell`编程进行学习。 首先,环境变量是全局的,它们在整个...
本篇文章将详细介绍如何在Linux环境下正确地配置Java环境变量,包括`JAVA_HOME`、`PATH`以及`CLASSPATH`等关键变量的设置方法。 #### 1. 理解环境变量 在深入讨论如何设置之前,我们先来了解一下这些环境变量的...
在第1部分的预备知识中,课程可能会讲解"Linux环境的汇编语言"的定义和学习此课程的原因,同时推荐了相关教材和教学资源。这部分还会涉及Linux的安装和使用,包括如何通过命令行进行日常操作,以及如何使用各种命令...
在Linux环境中安装Java 1.8是开发和运维工作中的常见任务,对于使用Java作为主要开发语言的项目尤其重要。本文将详细介绍如何在Linux系统上安装Java 1.8,以及涉及的相关知识点。 首先,Java Development Kit (JDK)...
1. **使用 `echo` 命令检查**:通过执行以下命令来验证环境变量是否正确设置: - `echo $JAVA_HOME` - `echo $CLASSPATH` - `echo $PATH` 2. **检查JDK安装状态**:运行 `java -version` 命令以确保JDK已成功...
Linux 环境下配置 Tomcat 服务器需要安装 JDK 和 Tomcat,然后设置环境变量和启动 Tomcat。通过这篇文章,我们了解了 Tomcat 的基本概念、安装 JDK 和 Tomcat 的步骤,以及设置环境变量和启动 Tomcat 的方法。
setenv命令的英文全称为“set environment variable”。该命令为 tsch 中查询或设置环境变量的命令。可以在线程里用这个命令设置环境...与该功能相关的Linux命令:read – 读取单行数据which命令 – 查找文件bzcmp命
我们将探讨BES的版本(如BES2500和BES2300),以及在Linux环境下设置开发环境所涉及的关键步骤。 首先,我们需要了解BES2500和BES2300的区别。BES2500可能是BES系列的一个较新版本,它可能包含了更多改进的功能、...
本手册旨在指导用户在 Linux 环境中安装和配置 Tomcat 服务器, step-by-stepguiding users through the process of installing and configuring Tomcat on a Linux environment. 知识点一:下载和安装 Tomcat 在...
在Linux环境下配置Java环境并安装JDK以及Tomcat服务器是一项重要的技能,对于开发基于Java的应用程序至关重要。本文将详细介绍在Linux系统(以CentOS为例)上安装Java Development Kit (JDK) 和Apache Tomcat的过程...
在Linux操作系统中,环境变量扮演着至关重要的角色,它们定义了用户进程的运行环境,包括查找可执行...通过本文的分析,我们可以明确问题的根源,并采取适当的措施解决这个问题,确保在Linux环境中顺利地执行各类命令。
Linux 的 source 命令是一种常用的命令,用于读取并执行指定文件中的命令,但是有时候在使用 source 命令时,可能会出现找不到命令的情况。今天我们将为大家介绍 Linux 的 source 命令找不到的解决方法。 问题描述 ...
通过对Linux环境下环境变量的深入了解和合理设置,可以极大地提高系统的稳定性和效率。在ARM架构的环境中,这一过程同样适用,而且还需要特别注意与硬件平台相关的特殊性。通过上述方法和实践案例的学习,相信读者...
本文将详细介绍LINUX环境中环境变量的基本概念、配置方法以及一些实际应用场景。 #### 一、环境变量简介 环境变量是操作系统或应用程序用来保存某些状态或路径信息的一种机制。它们通常由名称和值组成,并且在整个...
在Linux环境下配置Tomcat和JDK是部署Java应用的基础步骤,这一过程涉及到JDK的安装、环境变量的设定以及Tomcat服务器的配置。下面将详细阐述这些知识点。 ### JDK安装与环境配置 #### 安装JDK 在Linux环境下安装...
### dd命令烧写Linux系统到SD卡的知识点详解 #### 一、理解U-Boot如何到达SD卡的原理概述 1. **S3c2416架构下的启动过程** - **BL0 (Boot Loader Stage 0):** - **定义与功能:** BL0指的是S3c2416处理器内部ROM...
### Linux环境下安装JDK知识点详解 #### 一、前言 在Linux环境下安装JDK(Java Development Kit)是一项常见的操作任务,尤其对于开发者而言尤为重要。本文将基于提供的文件信息,详细解析在Linux系统中安装JDK的...
这涉及到下载JDK安装包并进行安装,然后配置Java环境变量,包括JAVA_HOME(指向JDK安装目录)、JRE_HOME(指向JDK中的Java Runtime Environment目录)、CLASSPATH(指向JDK相关的库路径),以及PATH(将JDK的bin目录...
在Linux环境下,Eclipse提供了一个高效且灵活的工作空间,帮助开发者编写、调试和部署应用程序。下面将详细介绍如何在Linux系统中安装和使用Eclipse。 首先,你需要下载Eclipse的Linux版本。通常,Eclipse会提供...