Shell Learning--variables

Source: Internet
Author: User

1. In bash, the value of each variable is string 2, view the environment variable of a process cat/proc/$PID/environ | TR ' \ s ' \ n ' 3, variable assignment 3.1, var=value, note that var = value is not an assignment operation, but an equality operation 3.2, if value contains any white space characters, you must use single or double quotation marks 4, print variables [[email protected]978]# var=value[[email protected]978]# Echo $varvalue [[email protected]978]# Echo ${var}value5, in Echo or printf, to reference a variable, use double quotation marks [[email protected]1]# fruit=apple[[email protected]1]# echo "We have five $fruit (s)" We have five Apple (s) [[email protected]1]# 6, environment variable 6.1, environment variable is not defined in the current process, inherit from the parent process of the variable 6.2, export to set the environment variable, after the setting, any application executed from the current shell script will inherit the variable 6.3, after giving the command to execute, The shell automatically finds the corresponding executable file in the directory list contained in the PATH environment variable 7, obtaining the variable length [[email protected]1]# var=124hello[[email protected]1]# length=${#var}[[email protected]1]# Echo $length 8[[email protected]1]# echo ${#var}88, common environment variables [[email protected]1]# Echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin[[email protected]1]# Echo $HOME/root[[email protected]1]# Echo $SHELL/bin/bash[[email protected]1]# Echo $UID 09, set, env, and export differences 9.1, set shows the current shell variables (private variables), including the current user's variables, non-homogeneous shell has different private variables, bash, ksh, CSH shell Private variables are different 9.2, env displays the current user's variable 9.3, export shows the currently exported to the user variable shell variable 10, by setting the PS1 variable can be set bash hint string 11, using the function to add environment variables [[email protected]~]# prepend () {[-d] "$"] && eval $1=\ "$": ' \$$1\ ' && export $;} [[email protected]~]# t1=/home[[email protected]~]# prepend t1/root[[email protected]~]# echo $T 1/root:/home But if the initial value of T1 is empty, the result is as follows [[email protected]~]# t1=[[email protected]~]# echo $T 1 [[email protected]~]# prepend t1/root[[email protected]~]# Echo $T 1/root:[[email protected]~] #需要增加一个判断, introduced the form of Shell parameter extension ${param:+expr} If Param has a value and is not empty, the value of expr is used [[email protected]~]# prepend () {[-d ' $ $ '] && eval $1=\ ' $2\$\{$1:+ ': ' \$$1\}\ ' && export $;} [[email protected]~]# t1=[[email protected]~]# prepend t1/root[[email protected]~]# Echo $T 1/root[[email protected]~]#

Shell Learning--variables

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.