LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-04-2005, 11:10 PM   #1
jorisb
Member
 
Registered: Jan 2004
Distribution: Mandrake 10.1
Posts: 33

Rep: Reputation: 15
Bash Script, no new line for echo command


I need my script to show a percentage, I'd like the percentage be updated on the same line so that I can display some other information as well.
The echo is inside a loop.

Also.. is there a simple way to figure out how long the command took to execute?
 
Old 11-04-2005, 11:10 PM   #2
debianmike
Member
 
Registered: Sep 2005
Posts: 115

Rep: Reputation: 15
well, the time command may help you with the second question...
 
Old 11-04-2005, 11:15 PM   #3
jorisb
Member
 
Registered: Jan 2004
Distribution: Mandrake 10.1
Posts: 33

Original Poster
Rep: Reputation: 15
Can you tell me how to use it?
 
Old 11-04-2005, 11:38 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
The man pages are your friend... I promise (man echo)

Try this in your script:
Code:
echo -ne "${percentage}   ${other_data}\r"
Substitute the appropriate variables of course

As for the time command: (man time)
Code:
time cat /path/to/some/document.txt
<document text omitted>
real    0m0,059s
user    0m0.002s
sys     0m0.002s
Of course, those numbers will vary depending on the command, load on the system, etc. It's likely you're only interested in the "real" time. THe man page has all the details.
 
Old 11-04-2005, 11:53 PM   #5
jorisb
Member
 
Registered: Jan 2004
Distribution: Mandrake 10.1
Posts: 33

Original Poster
Rep: Reputation: 15
Thanks, I know man pages can be usefull.. and I was trying but I just needed an example.

I was missing the quotations.. obvious.. but not to me at the time.
 
Old 11-05-2005, 12:08 AM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Don't worry. The man pages seem a bit rough to handle for a while, but you just have to stick with it. The echo and time man pages are relatively simple. You can always just experiment as well. The echo command isn't going to crash your computer It's all a part of learning the ropes.

As for the quotes with the echo command, they actually aren't necessary. I add them out of habit. This will do the same thing:
Code:
echo -ne ${percentage}   ${other_data}\\r
The only difference is an extra backslash. The reason for that involves how bash tries to interpret/process commands entered before actually executing them. The details aren't that important. Just keep in mind that if you use a backslash outside of double- or single-quotes, then you may have to sprinkle in some more backslashes to make things work as expected.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 06:07 PM
escape string in bash script so it can be used in command line BuckRogers01 Linux - Software 15 08-12-2010 09:38 AM
Bash script text line into an array toolshed Programming 1 06-13-2005 05:49 PM
Bash Scripting - echo command question gbhil Programming 2 04-27-2005 07:27 PM
CGI script problem: Send/Expect command echo on webpage rajatgarg Programming 2 07-11-2004 04:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration