shell(一) -- 变量作用领&命令替换&位置参数

变量作用域

num=10 #定义全局变量

export num #定义全局变量为环境变量

bash #进入子进程

exit #退出子进程

 

命令替换

begin_time=$(date) //系统时间赋值给begin_time参数

begin_time=$(date +%s) #系统时间戳,赋值给begin_time 。 $()只在batch shell中有效,反引号可在多种shell中使用

end_time=$(date +%s) #系统时间戳,赋值给end_time

remain_time=$((end_time-begin_time)) #获取剩余时间,(())是shell计算命令

 

位置参数

$n #n>=1, 在方法或shell脚本文件中表示参数位置

 

 

 

 

参考:http://c.biancheng.net/view/vip_4558.html

 

posted on 2023-04-16 10:49  周公  阅读(4)  评论(0编辑  收藏  举报

导航