Variables in Linux

Source: Internet
Author: User

The variables in Linux are divided into

Local variables, environment variables, local variables, positional variables, special variables


Local variables: Valid for the current shell process only, effective immediately

Usage: variable name = value

Reference: ${variable name}, greater than number can be omitted

Cases

[Email protected] ~]# Name=jerry[[email protected] ~]# echo $namejerry


Environment variables:

1. Valid for all child shells of the current shell and current shell, effective immediately, logout is invalid

Usage: Export Variable name = value

Cancel: unset variable name

Cases

[[email protected] ~]# export Name=andy[[email protected] ~]# bash[[email protected] ~]# echo $nameandy [[email protected] ~]# Exitexit

2, valid for all shells, write to file, command load or re-login takes effect

File All directories: Interactive/etc/profile,/etc/profile.d/*.sh or ~/.bash_profile, non-interactive/ETC/BASHRC, ~/.BASHRC

After writing, use: . File name or source file name to import, or you can log in again

There are many environment variables in bash, which are usually denoted by the command: Set,export, printenv,env to query


The following is a sequence of configuration file access for both interactive and non-interactive logon types

Interactive:/etc/profile-->/etc/profile.d/*.sh-->~/.bash_profile-->~/.bashrc--> ETC/BASHRC

Non-interactive: ~/.bashrc-->/etc/bashrc--> etc/profile.d/*.sh


Local variables

Variables in a function


Position variable: The first parameter that represents a reference

$, $2...${10} double-digit to use greater than sign


Special variables

$?: Execution status of last command 0 indicates success, greater than 1 means unsuccessful and corresponding error code

$#: Number of parameters

$* or [email protected]: all parameters



Variables in Linux

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.