---
title: "系统命令_$SECONDS"
author: "listen-raining"
date: "2016-10-19T16:59:22Z"
tags: []
categories: ["编程语言"]
slug: "seconds"
draft: false
lastmod: "2016-10-19T16:59:22Z"
id: 2331627
url: "https://listen-raining.iteye.com/blog/2331627"
---

$SECONDS : 这个脚本已经运行的时间(以秒为单位)



------------------------1--------------------------

#!/bin/bash
#seconds.sh
TIME_LIMIT=10
INTERVAL=1
echo
echo "Hit Control-C to exit before $TIME_LIMIT seconds."
echo

while 
do
   if 
       then
       units=second
   else
       units=seconds
   fi
   echo "This script has benn running $SECONDS $units"
   sleep $INTERVAL
done

echo -e "\a"

exit 0







------------------------2--------------------------

#!/bin/bash

a_method()
{
    for i in 1 2 3 4 5 6 7 8
    do
        echo "$i"

        sleep 1
    done    
}

a_method

echo "This scrpt has been running $SECONDS second."