`
- 浏览:
235092 次
- 性别:
- 来自:
北京
-
Shell Variable and Operator
- 变量是放在内存中的一定的存储单元,存储单元中存放着某个值,这个值可以改变.
- 本地变量
.本地变量在用户现在的SHELL生命期的脚本中使用.
.variable-name=value
.set 显示本地所有变量
.readonly variable-name 设置变量为只读
- 环境变量
.环境变量用于所有用户进程(经常称为子进程).登录进程称为父进程.SHELL中执行的
用户进程均称为子进程.不象本地变量(只用于现在的SHELL),环境变量可用于所有子
进程,包括编辑器,脚本和应用.
.$HOME/.bash_profile(/etc/profile) 设置环境变量的文件
.export 设置环境变量命令
.env 显示环境变量
- 显示变量
.echo $variable-name
.${variable-name:+value} 如果设置了该变量,则显示其值,否则为空.
.${variable-name:?value} 如果未设置该变量,显示用户定义的信息value.
.${variable-name:-value} 如果未设置该变量,则显示value
.${variable-name:=value} 如果未设置该变量,设置其值,并显示.
- 位置变量
.位置变量表示S0,$1,... ... $9
.在脚本中使用位置参数
招待脚本时 ./Parameter Test parm1 parm2 parm3
#!/bin/bash
#Parameter Test
echo "This is the name of the script:$0."
echo "This is the 1st position parameter: $1."
echo "This is the 2nd position parameter: $2."
echo "This is the 3rd position parameter: $3."
echo "This is the 4th position parameter: $4."
echo "This is the 5th position parameter: $5."
echo "This is the 6th position parameter: $6."
echo "This is the 7th position parameter: $7."
echo "This is the 8th position parameter: $8."
echo "This is the 9th position parameter: $9."
.向系统命令传递参数
./find.sh CNURevamp
#!/bin/bash
#find.sh
find /home/leo/svn/office/webapps -name $1 -print
- 标准变量
. bash 默认建立了一些标准环境变量,可在/etc/profile中定义.
EXINIT HOME IFS LOGNAME MAIL MAILCHECK MAILPATH TERM
PATH TZ PS1 PS2 EDITOR PWD SHELL MANPATH TERMINFO
- 特殊变量
.$# 传递到脚本的参数个数
.$* 以一个单字符串显示所有向脚本传递的参数,与位置变量不同,
此选项参数可超过9个
.$$ 脚本运行的当前进程ID号
.$! 后台运行的最后一个进程的ID号
.$@ 显示参数列表
.$- 显示SHELL 使用的当前选项,与set命令相同
.$? 显示最后命令的退出状态,0表示没错,其它任何值表示有错误.
- 影响变量的命令
.unset variable-name 清除变量
.declare
-- 设置或显示变量
-- -f 只显示函数名
-- -r 创建只读变量(typeset
-- -x 创建转出变量(export)
-- -i 创建整数变量
-- 使用+代替-,可以颠倒选项的含义
.export
-- 用于创建传给子SHELL的变量
-- --表明选项结束,所有后续参数都是实参
-- -f 表明在'名-值' 对中的名字是函数名.
-- -n 把全局变量转换成局部变量.命令的变量不再传给SHELL.
-- -p 显示全局变量列表
.shift [n]
-- 用于移动位置变量,调整位置变量,使$3的值给$2,$2的值给$1.
.typeset declare的同义词.
- 引号
.双引号:可引用除字符$ ` \ 外的任意字符或者字符串
.单引号:可引用任意字符或字符串
.反引号:用于命令替换.设置系统命令的输出到变量.SHELL将反引号中的内容作为一个
系统命令,并招行其内容.
.反斜杠:如果一个字符有特殊含义,反斜线防止SHELL误解其含义,即屏蔽特殊含义.
特殊含义字符:& * + ^ $ ` " | ?
- 运算符
. $[] 表示形式告诉SHELL对方括号中的表达式求值. 例: $[2+8]
$[] 可以接受不同进制的数字 [10#n]表示从2到36的任何进制.
. 赋值运算符 let cont=$cont + $change
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
Tektronix 2465B Options and Operator Manual 泰克 400M 示波器2465B的操作使用手册 我个人自己制作的,花了几个小时弄的,希望能帮到大家。 首先该资源非常不好找,其次该资源在国外要钱买,自己想办法弄出图片...
Shell-operator是用于在Kubernetes集群中运行事件驱动脚本的工具。 该运算符不是特定软件产品的运算符,例如prometheus-operator或kafka-operator 。 Shell-operator通过将脚本视为事件触发的钩子,在Kubernetes...
LASSO是由1996年Robert Tibshirani首次提出,全称Least absolute shrinkage and selection operator。该方法是一种压缩估计。它通过构造一个惩罚函数得到一个较为精炼的模型,使得它压缩一些回归系数,即强制系数...
HAAS SERVICE AND OPERATOR MANUAL ARCHIVE.2007版,417页
利用瓦片级和算子级并行性实现通用可伸缩图神经网络加速_ZIPPER Exploiting Tile- and Operator-level Parallelism for General and Scalable Graph Neural Network Acceleration.pdf
Operator Theory And Numerical Methods (Studies In Mathematics And Its ApplicationsOperator Theory And Numerical Methods (Studies In Mathematics And Its Applications
主要介绍了shell脚本报错:"[: =: unary operator expected"解决办法的相关资料,需要的朋友可以参考下
Fuzzy Linguistic Hybrid Geometric Aggregation Operator and Its Application to Group Decision Making,卫贵武,,With respect to multiple attribute group decision making problem with triangular fuzzy ...
备份存积分
参考官方文档Compile and install from master 官方给的Prerequisites为: git mercurial version 3.9+ bazaar version 2.7.0+ go version v1.13+. 其中mercurial和bazaar我都没装,operator-sdk也编译安装成功了。 ...
西门子_Clock Synchronization between a HMI Operator Panel and a SIMATIC PLCpdf,
new操作符(new operator)和operator new的区别,会很有帮助
Some geometric aggregating operator and their application to dynamic multiple attribute decision making in intuitionistic fuzzy setting,卫贵武,,The dynamic multi-attribute decision making problems ...
Reminiscences of a Stock Operator by Edwin Lefevre, 75th anni. edition
chaosblade-operator镜像
进口国产数控机床维修手册.电路图.操作手册
find_marks_and_pose (Operator)中文翻译 Extract rectangularly arranged 2D calibration marks from the image and calculate initial values for the external camera parameters. 从图像中提取矩形排列的二维...
System Storage TS3100 Tape Library and TS3200 Tape LibrarySetup, Operator, and Service Guide
aerospike-operator.tar