2018/01/01

January frist 2018 monday ;

Weather : clear !
1、需求:
请详细查看如下几个数字的规律,并使用shell脚本输出后面的十个数字。
10 31 53 77 105 141 …….

[root@Dasoncheng sbin]# cat n.sh 
#!/bin/bash
sum=10
m=20
for i in `seq 0 14` ;
do 
  n=$[$m+2**$i]
  sum=$[$sum+$n]
  if [ $i -ge 5 ];
  then
      echo "$sum"
  fi
done

2、需求:
写个shell,看看你的Linux系统中是否有自定义用户(普通用户),若是有,一共有几个?

[root@Dasoncheng sbin]# cat o.sh 
#!/bin/bash
##How to collect zhe user who uid exceeds one thousand ;
n=`awk -F ':' '$3>1000' /etc/passwd |wc -l`
if [ $n != 0 ];
then
    echo "The number of general user is $n"
else
    echo "There is no general user."
fi
参考答案:

1、
试题解析:
我想大多数人都会去比较这些数字的差值:
10 31 53 77 105 141
21 22 24 28 36
但是这个差值看,并没有什么规律,而我们再仔细看的时候,发现这个差值的差值是有规律的:
10 31 53 77 105 141
21 22 24 28 36
1 2 4 8

#! /bin/bash
x=21
m=10
echo $m
for i in `seq 0 14`; do
 j=$[2**$i]
 m=$[$m+$x]
 echo $m
 x=$[$x+$j]
done

2、

##假设所有普通用户都是uid大于1000的
#!/bin/bash
 n=`awk -F ':' '$3>1000' /etc/passwd|wc -l`
 if [ $n -gt 0 ]
 then
     echo "There are $n common users."
 else
     echo "No common users."
 fi

转载于:https://my.oschina.net/u/3651233/blog/1600704

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值