Fedora Linux Support Community & Resources Center
  #1  
Old 8th May 2004, 05:41 AM
Erik-joix Offline
Registered User
 
Join Date: May 2004
Location: Berlin, Germany
Age: 38
Posts: 32
countdown

Hi guys.
I don't consider myself to be a coder/programmer but i know some about it. I passed a C++ class a while back. Anyway, i wrote this little script some time ago to basically make it easyer for myself to look for certain types of files and delete (shred) them. I put in a little countdown but i want to make it look nicer. Here's how it is right now.
Code:
echo -e "You have entered\n"
echo -e "Directory: " "\033[0;34m$location"; tput sgr0
echo -e "File type: " "\033[0;34m$type\n"; tput sgr0
echo "Preparing search....."
sleep 5
echo -e "Search starts in ""\033[0;31m3"; tput sgr0 "seconds"
sleep 1
echo -e "Remaining: ""\033[0;33m2"; tput sgr0
sleep 1
echo -e "Remaining: ""\033[0;32m1\n"; tput sgr0
sleep 1

find $location -name "*.$type" >$type-list.txt
This creates a new line after every second but i want it to stay one line and just change the number behind "Remaining". How could i do that?

The output looks like this.

You have entered

Directory: /home
File type: mp3

Preparing search.....
Search starts in 3
Remaining: 2
Remaining: 1


Last edited by Erik-joix; 10th May 2004 at 02:36 AM.
Reply With Quote
  #2  
Old 10th May 2004, 03:49 AM
theurge Offline
Registered User
 
Join Date: Mar 2004
Location: Kansas City, USA
Age: 37
Posts: 46
Ok, I found the solution. I had the idea, just not the right syntax with echo:

Code:
#!/bin/bash
#
# Demonstrates using backspace in a shell script
#
# theurge14@yahoo.com  Sun May  9 21:50:22 CDT 2004

totalLoops=20
counter=1

echo Counting to $totalLoops!
echo
echo -n "Count =  "

while (( counter <= totalLoops ))
do
	if (( counter<10 )); then
		echo -n "$counter "
	else
		echo -n "$counter"
	fi

	(( counter++ ))
	sleep 1

	# Backspace twice over the number, see the man page on echo for more info
	echo -n -e \\b\\b
done

echo
echo "Done!"
The above script will do exactly what you are asking to do. Note this line:

Code:
      echo -n -e \\b\\b
There are your two backspaces. Apparently the octal code only works for printable characters.

Have fun!
Reply With Quote
  #3  
Old 10th May 2004, 04:00 AM
Erik-joix Offline
Registered User
 
Join Date: May 2004
Location: Berlin, Germany
Age: 38
Posts: 32
Thank you very much theurge!
This works like a champ.
Here is the part of the script that i altered.
Code:
echo -e "You have entered\n"
echo -e "Directory: " "\033[0;34m$location"; tput sgr0
echo -e "File type: " "\033[0;34m$type\n"; tput sgr0
echo "Preparing search....."
sleep 5
echo -e -n "Search starts in:""\033[0;31m 3"; tput sgr0
echo -e -n " seconds"
sleep 1
echo -e -n "\010""\010""\010""\010""\010""\010""\010""\010""\010""\010" "\033[0;33m2"; tput sgr0
echo -e -n " seconds"
sleep 1
echo -e -n "\010""\010""\010""\010""\010""\010""\010""\010""\010""\010" "\033[0;32m1"; tput sgr0
echo -e -n " seconds"
sleep 1

find $location -name "*.$type" >$type-list.txt
Reply With Quote
  #4  
Old 10th May 2004, 04:02 AM
theurge Offline
Registered User
 
Join Date: Mar 2004
Location: Kansas City, USA
Age: 37
Posts: 46
Aha! Looks like the octal does indeed work.

So either "\010" or \\b or "\b" is a backspace.

Cool to know. Thanks!

Last edited by theurge; 10th May 2004 at 04:05 AM.
Reply With Quote
  #5  
Old 10th May 2004, 04:05 AM
Erik-joix Offline
Registered User
 
Join Date: May 2004
Location: Berlin, Germany
Age: 38
Posts: 32
Quote:
Originally posted by theurge
Ok, I found the solution. I had the idea, just not the right syntax with echo:

Code:
#!/bin/bash
#
# Demonstrates using backspace in a shell script
#
# theurge14@yahoo.com  Sun May  9 21:50:22 CDT 2004

totalLoops=20
counter=1

echo Counting to $totalLoops!
echo
echo -n "Count =  "

while (( counter <= totalLoops ))
do
	if (( counter<10 )); then
		echo -n "$counter "
	else
		echo -n "$counter"
	fi

	(( counter++ ))
	sleep 1

	# Backspace twice over the number, see the man page on echo for more info
	echo -n -e \\b\\b
done

echo
echo "Done!"
The above script will do exactly what you are asking to do. Note this line:

Code:
      echo -n -e \\b\\b
There are your two backspaces. Apparently the octal code only works for printable characters.

Have fun!
When i posted i didn't see this one.
Anyway, i like this way more.
It looks more professional than what i did.
I'll try and implement your solution into my script by some time tomorrow.

Thanks for the help here!
Reply With Quote
  #6  
Old 10th May 2004, 04:07 AM
theurge Offline
Registered User
 
Join Date: Mar 2004
Location: Kansas City, USA
Age: 37
Posts: 46
Yeah it looks like we're playing post-tag here.

Probably replacing all those octals with "\b" would help shorten the script up.

Good luck.
Reply With Quote
  #7  
Old 11th May 2004, 05:26 AM
Erik-joix Offline
Registered User
 
Join Date: May 2004
Location: Berlin, Germany
Age: 38
Posts: 32
I implemented your idea into my script and hope that's alright with you.
I also altered it a little bit to fit my "colored text needs" and you're right. It did significantly shorten the script. Thanks again.
Code:
echo -e "You have entered\n"
echo -e "Directory: " "\033[0;34m$location"; tput sgr0
echo -e "File type: " "\033[0;34m$type\n"; tput sgr0
echo -e "Preparing search....."
sleep 3
echo -n "Search starts in:  "

while (( counter >= liftoff ))
do
	if (( counter>3 )); then
		echo -e -n "\033[0;31m$counter"; tput sgr0
	else
		if (( counter>1 )); then
			echo -e -n "\033[0;33m$counter"; tput sgr0
		else
			echo -e -n "\033[0;32m$counter"; tput sgr0
		fi
	fi
	(( counter-- ))
	sleep 1
	echo -n -e \\b
done

find $location -name "*.$type" >$type-list.txt
Reply With Quote
  #8  
Old 11th May 2004, 06:10 AM
theurge Offline
Registered User
 
Join Date: Mar 2004
Location: Kansas City, USA
Age: 37
Posts: 46
Of course I don't mind, don't mention it. On the contrary I'm rather flattered you used my code.

One comment I might add though on what you have now, on the 2nd nested if structure:

Code:
		if (( counter>1 )); then
			echo -e -n "\033[0;33m$counter"; tput sgr0
		else
			echo -e -n "\033[0;32m$counter"; tput sgr0
		fi
Looks like you have two identical echo statements there.

I wrote this in the original code to make up for the extra digit (when I reached ten) when I used the two backspaces.

I see you took the double backspaces out, but I also see you're counting down instead of up. I guess you're not using numbers greater than 10 so it isn't a problem, but then again I haven't run your code myself so I don't really know.

But anyway, I brought this up as you may decide to remove these lines of code as unnecessary and just stick with:

Code:
			echo -e -n "\033[0;33m$counter"; tput sgr0


Thanks for posting this, I enjoy shell scripting.

Last edited by theurge; 11th May 2004 at 06:13 AM.
Reply With Quote
  #9  
Old 11th May 2004, 01:12 PM
Erik-joix Offline
Registered User
 
Join Date: May 2004
Location: Berlin, Germany
Age: 38
Posts: 32
Quote:
Originally posted by theurge
[B]
Code:
		if (( counter>1 )); then
			echo -e -n "\033[0;33m$counter"; tput sgr0
		else
			echo -e -n "\033[0;32m$counter"; tput sgr0
		fi
Looks like you have two identical echo statements there.
I'm sure they aren't identical.
Reply With Quote
  #10  
Old 11th May 2004, 10:28 PM
theurge Offline
Registered User
 
Join Date: Mar 2004
Location: Kansas City, USA
Age: 37
Posts: 46
Late night. Sorry. Thanks.
Reply With Quote
  #11  
Old 12th May 2004, 03:40 AM
Erik-joix Offline
Registered User
 
Join Date: May 2004
Location: Berlin, Germany
Age: 38
Posts: 32
And there i thought it can't be done any better.
Wrong.
Code:
#!/bin/bash

clear
printf "%s" "The counter is now: "

for (( counter=1; counter<10; counter++ )) ; do
    printf "%d\b" "$counter"
    sleep 1
done

printf "\n"

exit 0
Reply With Quote
  #12  
Old 12th May 2004, 03:41 AM
Picomp314 Offline
Registered User
 
Join Date: May 2004
Posts: 532
counter++
word.
Reply With Quote
  #13  
Old 13th May 2004, 12:44 AM
theurge Offline
Registered User
 
Join Date: Mar 2004
Location: Kansas City, USA
Age: 37
Posts: 46
Yes, a for loop works much better in this case.

This is fun though, change one small thing in your code:

Code:
#!/bin/bash

clear
printf "%s" "The counter is now: "

for (( counter=1; counter<13; counter++ )) ; do
    printf "%d\b" "$counter"
    sleep 1
done

printf "\n"

exit 0
And it produces this:

Code:
The counter is now: 1112
Reply With Quote
  #14  
Old 13th May 2004, 01:05 AM
Erik-joix Offline
Registered User
 
Join Date: May 2004
Location: Berlin, Germany
Age: 38
Posts: 32
Talking


yes, this code is not supposed to count into the 2 digit region.
Reply With Quote
Reply

Tags
countdown

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
When should the countdown banner for F11 come out? dragonbite Fedora Focus 1 10th March 2009 10:27 PM
Live CD Boot Countdown stevedavies Using Fedora 0 27th February 2009 06:52 PM
Countdown toti28 Using Fedora 2 10th August 2007 05:56 AM
Boot countdown timer bosjef Installation, Upgrades and Live Media 2 13th October 2006 01:26 PM


Current GMT-time: 10:19 (Tuesday, 21-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Trezzano sul Naviglio - Pavia - Ulaanbaatar Instagram Photos