bash中一切变量都是以字符串的形式存储,env命令可以查看与此终端进程相关的环境变量。

man bash

查看一个进程的环境变量

1.获得程序的PID,例如Java
# pgrep java
23492

2.查看对应的环境变量
# cat /proc/23492/environ
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqMAAACHCAIAAACtX8c2AAAgAElEQVR4nO1dzZnkqg51BDeCWXszEUwEvfG2I3ECLw2ncJNwEjeFimPewn9I6A+Dq1xd53yzmK7CQgihA8IFXUfx69/v77/f33///Ook/P799d/X13+/82/++d/X99/vb/bV799ff7+//379/u0XWD/47+vrv+NPqbCi2/r4ov/3998/f/7d/y8IlCv6/iMouXz4L692s5Ws7fbt99f//iltRVP8+iOqsTSK/yvXapgej2noumF6zGMvl+nH+TEN6qMWxnkex+kxj0sN0yRKiir6mEfze0W0oj8tsLU+/X9cAgAAwNNwmum7g2W3Zzcu2TnGLXCU2Wh1nR/8/f7zfXzLSSvBXv77318HmUkKW0xPeF1hyoTLF90kU2xf0bmCMEWQTNEINtN/ff2XML3SszbG+bGysUL0Os8J7DvOhHCH6fF4rKLT/5djeVqh2+VLdSrAZgHDlErKqV0ge1MCAADAM6Ex/a9/Ez74q3LDQbTKYtotsDOTXMXGiAuDCnkCUmATlc0b1IbIK12Ly3OGVmqhLRUqumiVr85UuJ6naL7rVA7d2ZODlmTFGEP243x8Nkwnib4fZ616oofOvURCUi7RftEsLUjEaRIAAACeDGdNfwdwjryxqreAyvTr1//KUxkAAADgZ+INmB4og8P0AAAAwGeBZumVN+OAtwBNfoDpAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPgjrabLbv+yQWhv4cQEAvDt6dpIiAADvBevc++6g+fRw3FKyD1UEPAc4EB4oB5geAN4ayzEvKgHzc+8rbosB0y948Rl5YHoAAIAn49XJbZvps29fy/T0EH5J1ZNbDG3gnpzD9kFewvdtmX69MefcFTjPgqZkcjC+fw+P2cRx1mQcx/TLInwdvFYAAHB/qKfhpqzw32/CIsnNKDU33LA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J4YVa7C/qR8KFPkRLPyYUQPtpr4/QCGcP3XqNK5aomAcZIPsZIq8ZtpSwgoKVVxMhI1GDdtD1TPoJ1jxlyYlTzuo5KfzkWLJWq7O1FA6N9pcAev24pdQn7Y8maZc25PR9abwfNJly/OjgvSu8LflyPkUYCJFzK9q8N2SqlWhfwYuVYhAvZ7dn4uMGvUcveHW6NwE4WpAT8Q3jkj2lEyf4AfMi/Ztuu864AizSw8c561SrB1sUcV2V7BlUzvnP8v2VnUZpznaZJuFtm+9Y1wurvzm4GkE+iNweu1Ijt5fyd6Yjrfo7yR9T6o9cmacdHg1PpahD3qyRCmIUbBl+l7c6afBvYdqUKJiYVKZC5L9fGvVahkeqH5gXHlKZk+ELhpylDGKn8t02uaO7g102t3+h21BZl+ve1Jbey1TC/cX5INCnvwOq0YJpZ2WqqYpgKmD42s9wGYPuJRdfg/qWeNxTg1g8oAAAAASUVORK5CYII=" alt="" />

3.将输出格式化,这样查看会比上图清晰
# cat /proc/23492/environ |tr '\0' '\n'
“^@”将变换成换行符
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA1EAAABNCAIAAADIG3mAAAATfklEQVR4nO2dyXnjOBBGGcFE0GdeHEFH4AuvjoQJTBpIYZJgEp2C4ug5cMNSG0VKlu33vj60RSyFRcCvAkB03T0M6baSBi3QOJmPs5Smsb/LjJMM6bNyPkQ/Tm41elht0Y+T35hfn5PFPN8KoRSGdLulcZwaI/txuk2jELz9EAAAwCbTccuE034yM06rTlMV2xrVm5CGJE/B2QR9WybBMlRhW57LEnMaxyQHaFLfA/Vi8r5Uuk3j9mdERUrqQ5fRllYoqyGlSahwuy124Ttb1eaktUWswwRqsozX9LRwRVn4xTTj2t1lDzB/2MhLN4WFfhV7Q6pNvED4AwAA7AjyonGG9bnPaJ7MxMlo0YNedsLMN39apVTP+lmARjjWEQS3iVg02UKpdKXl/TjdpunQpCym24+TYJCq+WphUNdbGVJ81I9TU6+FAU5bRDqMXYq+bpyqNQ9UlI5bz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5efnlQ86WhSkXQfMuN46LBy03Z2SeLt9FI8JU1X339ep0+S8gAAABwDFvzKfdq5bLGkzi72DI13yrpmliNoY3F8wfZx3Pig6P54kgiS1sGtyukWGaeUpqE68PXMNLN4nnpi5vqq/yz5esRtyMAAAA4mk+XL7mEGlLM5aSltmaYm9JItNKqQg8t8bbkl78VzSdYUW0YrHYdrgJLVFeCkFQrrRbQ7Sp5HlJ81I9TJTsrA+o0ZwGJ5gMAAPjxiAccNHW1U+mayrekL0pami8PUKupciG2fLpqxTn6vBrdd43mO3V2Y5d32QWzcnnCmk9H1Xx1Pu1ZmyYW2wsBAACgu8TPV9HPvqb2qav5MmlVpS8o08LfteuxaVozifv5ImTOyNW71ladWcy2HKqqi2g+IYxiEAAAAIB3huOgK0tN1IpVZLhELTRfG7H4pNzJt6lBdz/fFiCwtrvmOKRbGuaImhM0LCr1NXFf84mHPNB8AAAAoHH23K6ocE5oviVULtHEePV5kFbqxDVfjHHaTgcP6TalpEg7pZhKKUSRZmu+zNXYPjlSIgAAAPg5nH0/X1++jm/9RFJDMc3Xdd04TVMmhrTzE4VD7/GaL5dauuwyNV+wooyTF319WndIhRXy2xPZ0AcAAPCjaW4Lyz+oTkloByBWt5y1Ta3djbclXiyrFq+I2Y5lNJHUezXEAGnQ7+E4pPmKfYrZSQ6tjEJJU/L388k1oufi1jZ6DwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH4o/wMB2LCs3Qac4wAAAABJRU5ErkJggg==" alt="" />

变量赋值
var=varlue,如果value不包含空白字符,则不必加单引号或者双引号
var = value 是相等操作,注意区分,很多人这个地方发生混淆

输出变量
echo $var 或者 echo ${var}
例如:

# var=apple
# echo "${var}(s)"
apple(s)

变量字符串的常用操作

[root@Director ~]# var="hello world"

[root@Director ~]# echo ${#var}                         #计算字符串的长度,类似于"wc -m"-1;expr length "$var"

[root@Director ~]# echo ${var:}                        #从第二个字符串之后开始取,不包括第二个字符串。
llo world [root@Director ~]# echo ${var::} #从第二个字符串之后开始取,取两个字符,相当于"echo $var|cut -c 3-4"
ll [root@Director ~]# echo ${var#hell} #字符串开头删除最短匹配的字符
o world [root@Director ~]# echo ${var%ld} #从结尾开始删除最短匹配的字符
hello wor [root@Director ~]# echo ${var/world/linux} #替换匹配字符,类似 “echo ${var}|sed 's/world/linux/'”
hello linux [root@Director ~]# echo ${var/#hello/linux} #前缀匹配,则替换
linux world [root@Director ~]# echo ${var/%world/linux} #后缀匹配,则替换
hello linux [root@Director test]# echo $gender [root@Director test]# echo ${gender:-female} #变量未赋值,则定义一个值
female [root@Director test]# echo $gender [root@Director test]# echo ${gender:=female}       #变量未赋值,则定义一个值,并传递给它 
female [root@Director test]# echo $gender
female [root@Director test]# echo ${gender-male}        #变量未定义,则给予定义,若定义了则取原来的值
male

应用场景:

1.防止$path未定义,而删除了根目录或者root目录

[root@Director /]# find  ${path:=/test} -name "*.bak"|xargs rm -rf  

2.打印出文件或目录的后缀

[root@Director test]# jarName=app_20160807.jar
[root@Director test]# echo ${jarName:((${#jarName}-))}
jar

特殊变量

$PS1         系统默认:PS1="[\u@\h \W]\$"
$UID    为0时代表root用户

$TMOUT    终端timeout时间

$0,$* ,$@ , $#

[root@Director sbin]# cat /usr/local/sbin/test.sh
#!/bin/bash
echo '$0=' $0 #脚本的名称
echo '$1=' $1 #运行脚本的第n个参数
echo '$#=' $#     #运行脚本参数的个数
echo '$*=' $*     #所有参数当成单个字符串,很少使用
echo '$@=' $@     #所有参数
basename $0       #获取文件名
dirname $0       #获取文件的目录
[root@Director sbin]# sh /usr/local/sbin/test.sh aa bb
$= /usr/local/sbin/test.sh
$= aa
$#=
$*= aa bb
$@= aa bb
test.sh
/usr/local/sbin

 进程状态变量

 $?  获取执行上一个命令的返回值(0为成功,其它为失败)

$$ 获取当前shell的PID

$_ 获取之前命令或脚本的最后一个参数

!$ 执行上一个命令  

shell脚本学习总结05--变量与环境变量的更多相关文章

  1. Linux Shell脚本在service模式下的环境变量

    普通Shell脚本在终端下运行时,环境变量来自于init/profile/.bash_profile等,就是在当前终端下可以得到的环境,比如PATH.在service模式下,脚本运行在受限的环境中:比 ...

  2. shell脚本学习总结02--数组

    bash同时支持普通数组个关联数组,普通数组只能使用整数作为数组的索引,关联数组可以使用字符串作为数组的索引. 数组的定义方法: 在单行中使用一列值定义一个数组 [root@new ~]# array ...

  3. shell脚本学习-变量

    跟着RUNOOB网站的教程学习的笔记 shell变量 shell变量的命名 定义变量时,变量名不加美元符号($,PHP语言中需要),如: name="runoob" 注意,变量名与 ...

  4. shell 脚本学习之一 ------let,echo,变量

    转自:http://blog.chinaunix.net/uid-26827001-id-3154024.html 首先看到好多以这样开头的    #!/bin/bash   这个是告诉系统 解释此脚 ...

  5. shell脚本学习(一)

    Shell脚本最常用于系统管理工作,或者用于结合现有的程序以完成小型.特定的工作. Shell的特点有: 1. 简单性 2. 可移植性 3. 开发容易 [什么是shell] 简单点理解,就是系统跟计算 ...

  6. shell脚本学习笔记(符号)

    shell脚本的学习: 1.Shell的作用是解释运行用户的命令,用户输入一条命令,Shell就解释运行一条,这样的方式称为交互式(Interactive),Shell还有 一种运行命令的方式称为批处 ...

  7. shell 脚本学习

    Shell简介 概述 Shell是一种具备特殊功能的程序,它提供了用户与内核进行交互操作的一种接口.它接收用户输入的命令,并把它送入内核去执行.内核是Linux系统的心脏,从开机自检就驻留在计算机的内 ...

  8. 【shell脚本学习-1】

    Shell学习笔记 简介: Shell 是一个用C语言编写的程序,它是用户使用Linux的桥梁.Shell既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个 ...

  9. Shell脚本学习指南笔记

    Shell脚本学习指南 作者:Danbo 2015-8-3 脚本编程语言与编译型语言的差异 许多中型.大型的程序都是用编译型语言写的,例如:C.C+.Java等.这类程序只要从源代码(Source C ...

随机推荐

  1. android多线程进度条

    多线程实现更新android进度条. 实例教程,详细信息我已经注释   android多线程进度条   01package com.shougao.hello; 02 03import android ...

  2. IIS发布.net core mvc web站点

    这里只有操作步骤! 第一.查看IIS是否安装了 AspNetCoreModule,查看路径:IIS->模块 查看 安装步骤 下载网址:https://www.microsoft.com/net/ ...

  3. python ichat使用学习记录

    1.OSError: [WinError -2147221003] 找不到应用程序: 'D:\\python\\ichat\\qrcode.jpg' 原因是该库中没有windows系统如何打开二维码图 ...

  4. 转:Mosquitto配置----日志设置

    1.mosquitto的日志输出方式简介 mosquitto是一个纯C的代码,它的日志输出支持若干中日志输出方式,通过修改配置项:log_dest即可完成对各种日志输出类型的切换,常见的日志输出类型有 ...

  5. Oracle开发者守则

    下面为Oracle大师级语录: Oracle Database developers should follow is to do everything they can in SQL. What t ...

  6. SIFT 、Hog 、LBP 了解

    SIFT.HOG.LBP,这三者都属于局部特征. 一.三者原理上的区别 1.SIFT:Scale-Invariant Feature Taransform,尺度不变特征变换. 尺度空间的极值检测:搜索 ...

  7. 非常简单的一个函数 竟然一直没有使用 find()

    find: 在非string类型的容器里,可以直接找出所对应的元素. find函数需要几个参数:迭代器,下标值,所要找的元素 vector<int> a; find(a.begin(),a ...

  8. linode使用apt更新时停止的错误

    使用ubuntu在更新系统时候,有时候会出现这样的问题: 0% [Connecting to security.ubuntu.com (2001:67c:1560:8001::14)] 问了下客户,他 ...

  9. 【C语言】C语言程序所占内存分类

    参考"http://blog.sina.com.cn/s/blog_63d4849c01014qg3.html" C语言内存分为5部分:堆.栈.全局(静态)区.常量区(只读)和代码 ...

  10. 删除节点removeChild()

    http://www.imooc.com/code/1700 删除节点removeChild() removeChild() 方法从子节点列表中删除某个节点.如删除成功,此方法可返回被删除的节点,如失 ...