Unix Programming - A simple bash script

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > March 2005 > A simple bash script





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author A simple bash script
Phoe6

2005-03-17, 5:55 pm

Hi Group.

I just want to catch something interesting, so I wrote this:

#!/bin/bash

while [ $(date +%s) != 1111111111]
do
echo "Not yet!"
done

echo "Unix TIme"

date +%s

echo "date and time"
date
echo "thats history!"


I am facing problem at the statement

while [ $(date +%s) != 1111111111]

whats wrong with this.

I am a newbie bash scripter.

Kindly help me with this.

Senthil

Måns Rullgård

2005-03-17, 5:55 pm

"Phoe6" <orsenthil@gmail.com> writes:

> Hi Group.
>
> I just want to catch something interesting, so I wrote this:


[...]

> I am facing problem at the statement
>
> while [ $(date +%s) != 1111111111]
>
> whats wrong with this.


You need a space before the ].

--
Måns Rullgård
mru@inprovide.com
Floyd L. Davidson

2005-03-17, 5:55 pm

"Phoe6" <orsenthil@gmail.com> wrote:
>
>I am facing problem at the statement
>
>while [ $(date +%s) != 1111111111]
>
>whats wrong with this.


You should have gotten an error message that is rather
explicit, no? Put some white space after the number:

while [ $(date +%s) != 1111111111 ]

Actually, what you almost certainly want is

while [ $(date +%s) -lt 1111111111 ]

Otherwise it is possible to miss that one precise time, and continue
looking forever.

--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@barrow.com
Phoe6

2005-03-17, 5:55 pm

>> while [ $(date +%s) != 1111111111]
[vbcol=seagreen]
>You need a space before the ].


Thanks a lot. Its working now.

dunno why I missed this :-(

btw, do people here think of still better and interesting ways?
--------
#!/bin/bash
while [ $(date +%s) != 1111111111]
do
echo "Not yet!"
done
echo "Unix Time"
date +%s
echo "date and time"
date
echo "thats history!"
--

Måns Rullgård

2005-03-17, 5:55 pm

"Phoe6" <orsenthil@gmail.com> writes:

>
>
> Thanks a lot. Its working now.
>
> dunno why I missed this :-(
>
> btw, do people here think of still better and interesting ways?


Sure:

sleep $((1111111111 - $(date +%s) - 1)) # make sure we don't miss it
while [ $(date +%s) != 1111111111 ];
echo "Unix Time"
date +%s
echo "date and time"
date
echo "thats history!"

--
Måns Rullgård
mru@inprovide.com
Bill Marcum

2005-03-29, 6:21 pm

On 17 Mar 2005 13:38:36 -0800, Phoe6
<orsenthil@gmail.com> wrote:
>
>
> Thanks a lot. Its working now.
>
> dunno why I missed this :-(
>
> btw, do people here think of still better and interesting ways?


at $( date -d "Jan 1 1970 0000 UTC + 1111111111 seconds" )


--
"I deleted a file from my PC last week and I have just realized that I
need it. If I turn my system clock back two weeks will I have my file
back again?"
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com