centos 脚本练习4

前端之家收集整理的这篇文章主要介绍了centos 脚本练习4前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1, 练习 传递一个用户名参数与脚本,判断此用户名的基本组与用户ID是否相同,并显示结果; [root@localhost mscripts]# cat lx9.sh #!/bin/bash if ! id $1 &> /dev/null; then echo "No such the user." exit 9 fi if [ $# -lt 1 ]; then echo "please a username." exit 9 fi if [ id -u $1 -eq id -g $1 ]; then echo "same." else echo "different." fi

2, 传递三个参数与脚本,其一个为整数,第二个为自述去处符,第三个为整数;将计算结果显示出来,要求保留两位精度,形如 ./cale.sh 5 / 2 [root@localhost mscripts]# cat lx10.sh #!/bin/bash if [ $# -lt 3 ]; then echo "please input three argument." exit 9 fi echo "scale=2;$1$2$3;" | bc

3, 传递三个参数与脚本,参数均为用户名,将此些用户名的账号信息提取出来后放置于/tmp/testuser.txt中,并要求每一行行首有行号。 [root@localhost mscripts]# cat lx11.sh #!/bin/bash if [ $# -lt 3 ]; then echo "please input three arguement." exit 9 fi grep -n "$1" /etc/passwd >> /tmp/testuser.txt shift grep -n "$1" /etc/passwd >> /tmp/testuser.txt shift grep -n "$1" /etc/passwd >> /tmp/testuser.txt

原文链接:https://www.f2er.com/centos/375147.html

猜你在找的CentOS相关文章