小编Spi*_*let的帖子

shell 脚本中的两个字参数

我的 shell 脚本有问题。它应该读取参数:index、date、time1(间隔的开始)、time2(间隔的结束)。它应该计算用户(索引)在时间间隔 time1-time2 内登录给定日期的次数。

例如: 121212 "Jan 14" 00 12

这有效,但我对参数日期有问题。它不承认它是一个论点。它在 1 月和 14 日拆分,这是一个大问题。我在互联网上搜索了几个小时,但在任何地方都找不到解决方案。这是我的代码:

#!/bin/bash

read user date time1 time2
list=`last | grep ^$user.*$date | awk '{ print $7 }'`

start=$time1
end=$time2

echo "start $start"
echo "end $end"
count=0
for el in $list ;
do
      login=$el
echo "najava $najava"

checkIf(){
        current=$login
         [[ ($start = $current || $start < $current) && ($current = $end || $current < $end) ]]
}
if checkIf; then
        count=`expr $count + 1`
        ip=`last | …
Run Code Online (Sandbox Code Playgroud)

shell bash shell-script

6
推荐指数
1
解决办法
5596
查看次数

标签 统计

bash ×1

shell ×1

shell-script ×1