shell 脚本

[root@localadmain lisi]# mv shell01.sh /bin
[root@localadmain bin]# shell01.sh -bash: /bin/shell01.sh: 权限不够 [root@localadmain bin]# chmod a+x shell01.sh [root@localadmain bin]# ls -l | grep "shell*" -rwxr-xr-x. 1 root root 283 8月 10 19:34 shell01.sh [root@localadmain bin]# shell01.sh 报告班长任务在2020-08-10 19:45:11执行完毕!

将脚本转移到bin目录下,并将脚本的运行权限放开,就可以在任意位置执行脚本了!

[root@localadmain bin]# da=`date "+%Y-%m-%d %H-%M-%S"`
[root@localadmain bin]# echo $da 
2020-08-10 19-59-11

 [root@localadmain bin]# echo $da
 2020-08-10 19-59-11
 [root@localadmain bin]# ^C
 [root@localadmain bin]# echo ${da:4:2}
 -0
 [root@localadmain bin]# echo ${da:5:2}
 08

 

变量截取,echo ${a:5:2}:其中a为变量名,5是变量值的index值,2是截取的数量,即:在变量a的值中截取第5位开始的两个字符

 

posted @ 2020-09-25 15:49  shan_zhayidian  阅读(151)  评论(0编辑  收藏  举报