SHELL编程几个小例子
2016-12-15 23:26
211 查看
1.比较两个数大小
输出结果:
3.查找/root/目录下是否存在该文件
输出结果:
4.for循环的使用
输出结果:
5.命令行输入
输出结果:
6.从0.sh中读取内容并打印
输出结果:
7.打印当前用户
输出结果:
#/bin/bash echo "please enter two number" read a read b if test $a -eq $b then echo "NO.1 = NO.2" elif test $a -gt $b then echo "NO.1 > NO.2" else echo "NO.1 < NO.2" fi
输出结果:
3.查找/root/目录下是否存在该文件
#/bin/bash echo "enter a file name:" read a if test -e /root/$a then echo "the file is exist!" else echo "the file is not exist!" fi
输出结果:
4.for循环的使用
#/bin/bash clear for num in 1 2 3 4 5 6 7 8 9 10 do echo "$num" done
输出结果:
5.命令行输入
#/bin/bash echo "Please enter a user:" read a b=$(whoami) if test $a = $b then echo "the user is running." else echo "the user is not running." fi
输出结果:
6.从0.sh中读取内容并打印
#/bin/bash while read line do echo $line done < 0.sh
输出结果:
7.打印当前用户
#/bin/bash echo "Current User is :" echo $(ps | grep "$$" | awk '{print $2}')
输出结果:
相关文章推荐
- shell编程的几个例子来了解shell脚本
- 几个Shell编程例子
- Linux/Unix下grep命令使用的几个例子
- 内核定时器的使用(好几个例子add_timer)
- Swift for 的几个例子
- 几个很不错的.NET 相关的FAQ和例子代码的连接
- android中jsoup解析html的几个例子
- 几个基本的 Sql Plus 命令 和 例子
- shell编程的一些例子3
- 简单几个例子,教你用单例模式
- 很好的几个Managed Directx 例子
- scala 几个函数小例子
- php curl的几个例子
- windows编程几个小例子(一)
- JQuery解析XML数据的几个例子
- 几个loop细分的例子
- c++ 指针的几个测试例子
- opencv几个容易上手的简单的例子
- 学习shell编程的两个例子
- android之Uri的常用几个例子