<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Oliver Hansen &#187; count</title>
	<atom:link href="http://blog.oliverhansen.com/index.php/tag/count/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.oliverhansen.com</link>
	<description>A techie&#39;s not-so-technical weblog</description>
	<lastBuildDate>Sun, 27 Nov 2011 23:37:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>

	<item>

		<title>Small Bash Script to Count Seconds</title>

		<link>http://blog.oliverhansen.com/index.php/2008/03/25/small-bash-script-to-count-seconds/</link>

		<comments>http://blog.oliverhansen.com/index.php/2008/03/25/small-bash-script-to-count-seconds/#comments</comments>

		<pubDate>Wed, 26 Mar 2008 06:05:30 +0000</pubDate>

		<dc:creator>Oliver</dc:creator>

				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[unix]]></category>



		<guid isPermaLink="false">http://blog.oliverhansen.com/index.php/2008/03/25/small-bash-script-to-count-seconds/</guid>


		<description><![CDATA[<p>So the short story is I got a small UPS for my tv, xbox and cable modem so that I won&#8217;t be interrupted by small power hiccups. I decided I wanted to know how long my CRT tv and xbox would continue while watching a movie so I needed something to count with while I [...]]]></description>

	
		<content:encoded><![CDATA[<p>So the short story is I got a small UPS for my tv, xbox and cable modem so that I won&#8217;t be interrupted by small power hiccups. I decided I wanted to know how long my CRT tv and xbox would continue while watching a movie so I needed something to count with while I unplugged the power to test it.</p>
<p>Now I&#8217;m sure others have written scripts and I could probably have just used the clock on the computer but I decided it couldn&#8217;t be too difficult to figure out how to write a script to do this. I knew that I basically had to just create a loop that would print a number increasing by one and then wait one second and repeat. I just had to find the right commands. About 10 to 15 minutes of searching later and I had this:<br />
<span id="more-181"></span></p>
<p><code>#!/bin/bash<br />
#A very basic time counting script.<br />
#init value of x<br />
x=1<br />
#make y 1 less than x<br />
y=$((x-1))<br />
echo "Counting from $y..."      #Output what number we are beginning from<br />
        while [ $x -ge 0 ]      #While $x is >= 0 (all the time)<br />
        do<br />
                sleep 1         #Wait one second<br />
                echo $x         #Echo value of $x<br />
                x=$((x+1))      #Increase $x by 1<br />
        done<br />
</code></p>
<p>Some of the methods are a little different from what I am used to. To increase $x by 1, I am used to $x++. Bash is different I guess. There may be simpler ways to do this as well. If so, please leave a comment as I&#8217;m hopeful to learn.</p>
<p>Sample output:<br />
<code><br />
$ ./count.sh<br />
Counting from 0...<br />
1<br />
2<br />
3<br />
4<br />
5</code></p>
<p>Also note this script will continue to run until the user types the escape sequence &#8216;<em>Ctrl+C</em>&#8216;.</p>
<p>Some sources used to find what I needed:</p>
<ul>
<li><a href="http://www.panix.com/~elflord/unix/bash-tute.html">http://www.panix.com/~elflord/unix/bash-tute.html</a></li>
<li><a href="http://www.cyberciti.biz/tips/linux-unix-pause-command.html">http://www.cyberciti.biz/tips/linux-unix-pause-command.html</a> &#8211; Actually found the sleep command in the comments. Excellent site!</li>
</ul>
<div id="crp_related"><h2>Possibly Related Posts:</h2><ul><li><a href="http://blog.oliverhansen.com/index.php/2007/10/28/cron-is-different-in-freebsd-and-linux/" rel="bookmark" class="crp_title">Cron is Different in FreeBSD and Linux</a></li><li><a href="http://blog.oliverhansen.com/index.php/2007/09/27/updating-my-freebsd-installation-automatically/" rel="bookmark" class="crp_title">Updating My FreeBSD Installation &#8212; Automatically</a></li><li><a href="http://blog.oliverhansen.com/index.php/2008/02/19/force-freebsd-to-run-startup-scripts-without-rebooting/" rel="bookmark" class="crp_title">Force FreeBSD to Run Startup Scripts Without Rebooting</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>

	

		<wfw:commentRss>http://blog.oliverhansen.com/index.php/2008/03/25/small-bash-script-to-count-seconds/feed/</wfw:commentRss>


	
	</item>

	
</channel>

</rss>
