Hi all,
the error with the ! is simple: just dont put that character in the string
Its not the same runnning it separately from a command line than to execute them all togheter from a script (and that's why it didnt worked for you at first).
In regards with the ygloo script, its not working because you are using my example too literal
The second echo always add a newline so you get your clock to write the time one line below the other. You should have used just one echo:
Code:
#!/bin/bash
# a clock
seconds=0
minutes=0
hours=0
sec ()
{
while [ "$seconds" -le 59 ]; do
###
echo -en "$hours " :"$minutes " ."$seconds "
sleep 1
###
let "seconds += 1"
done
seconds=0
let "minutes += 1"
}
min ()
{
while [ "$minutes" -le 59 ]; do
sec
done
minutes=0
let "hours += 1"
}
hr ()
{
while [ "$hours" -lt 24 ]; do
min
done
hours=0
}
while true; do
hr
done
NOTE: I copied druuna idea of the modifications in bold! (good idea druuna!
)
I think both ideas are good, each one has its strengths and disadvantages: my idea is simpler and it can be used easily in any language. But, it is quite limited since you cant do much more than that (and if you happen to output a newline somewhere else in your code, your output would look messy).
druuna idea's of using tput is probably more flexible, since tput will let you do more things (I learned today about this command, but having a flash look at the man page, it seems that it has more things you can do with the screen). On the other side, it is a bit more complex to use, and its not that easy to use in other language (not that it matters for this case, but its something I like to take into consideration
)
In conclusion: we all learned new things today!
Cheers!