
Shell
卜塔
但行好事,莫问前程
展开
-
【Shell】特殊变量
1. $? 表示上一个命令退出的状态#正确命令的退出状态一般为“0”,不正确的命令会是一个不为“0”的数字#输入一个正确的ls命令[root@master ~]# ls [root@master ~]# echo $?0#输入一个错误命令[root@master ~]# l0-bash: l0: command not found[root@master ~]# echo $原创 2017-10-29 10:06:41 · 343 阅读 · 0 评论 -
【Shell】for循环
for循环是一种常用的语法,可用于数字、字符等的循环。当用于数字间循环时,比如,输出1~5之间的数字,两种写法如下:写法一:[root@master ~]# for i in {1..5}> do> echo $i> done12345写法二:[root@master ~]# for ((i=1;i<=5;i++))> do> echo $i> done1原创 2017-10-30 23:34:06 · 325 阅读 · 0 评论 -
【Shell】压缩相关命令
gzip:压缩文件zcat:查看压缩文件内容gunzip:解压文件[oracle@master test]$ lstestfile[oracle@master test]$ gzip testfile [oracle@master test]$ lstestfile.gz[oracle@master test]$ zcat testfile.gz This is Next...原创 2019-04-04 19:47:50 · 470 阅读 · 0 评论 -
【Shell】数值比较参数
Shell中的数值比较参数分为下面6种:Shell中的数值比较参数 参数 含义 -eq 等于 -gt 大于 -ge 大于等于 -lt 小于 -le 小于等于 -ne 不等于 例:[oracle@master test]$ cat testfile #!/bin/bas...原创 2019-04-07 07:43:32 · 2492 阅读 · 0 评论 -
【Shell】检查字符串大小
-n和-z可以检查变量中是否含有数据,其中:-n 非空则返回True-z 如果为空则返回True例子:[oracle@master test]$ cat testfile #!/bin/bash# Testing string lengthval1=testingval2=''if [ -n $val1 ]then echo "The string '$v...原创 2019-04-07 08:07:25 · 626 阅读 · 0 评论 -
【Shell】获取文件名和扩展名
不多说了,看代码体会吧。[oracle@master test]$ cat test.sh#!/bin/bashfile=test.shecho "文件名:${file%.*}"echo "扩展名:${file#*.}"[oracle@master test]$ sh test.sh文件名:test扩展名:sh[oracle@master test]$ cat test...原创 2019-05-22 20:19:20 · 3889 阅读 · 0 评论