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   周公  阅读(8)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示