shell备忘录

变量

环境变量说明
$HOME当前用户的home目录
$PATH以冒号分割的用来搜索命令的目录列表
$PS1命令提示符,例如:[\u@\h \w]$,给出用户名 机器名和当前目录名 后面跟一个$提示符号
$PS2二级提示符,用来提示后续的输入,通常是>字符
$IFS输入域分割符。当shell读取输入时,它给出用来分隔单词的一组字符,它们通常是空格 制表符和换行符
$0shell脚步的名字
$#传递给脚本的参数个数
$$执行当前shell脚本的进程号
参数变量说明
$1,$2, ...脚本程序的参数
$*在一个变量中列出所有的参数,各个参数之间用环境变量IFS中的第一个字符分隔开
$@它是$*的一种精巧变体,使用空格分隔各个参数

当函数被调用时,脚本程序的位置参数($* $@ $# $1 $2等)会被替换为函数的参数

条件比较

字符串比较说明
string1 = string2如果量个字符串相同则结果为真
string1 != string2如果量个字符串不同则结果为真
-n string如果字符串不为空则结果为真
-z string如果字符串为空则结果为真
算数比较说明
expression1 -eq expression2True if the expressions are equal
expression1 -ne expression2True if the expressions are not equal
expression1 -gt expression2True if expression1 is greater than expression2
expression1 -ge expression2True if expression1 is greater than or equal to expression2
expression1 -lt expression2True if expression1 is less than expression2
expression1 -le expression2True if expression1 is less than or equal to expression2
文件条件测试说明
-d fileTrue if the file is a directory
-e fileTrue if the file exists. Note that historically the -e option has not been portable, so -f is usually used.
-f fileTrue if the file is a regular file
-g fileTrue if set-group-id is set on file
-r fileTrue if the file is readable
-s fileTrue if the file has nonzero size
-u fileTrue if set-user-id is set on file
-w fileTrue if the file is writable
-x fileTrue if the file is executable
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值