Sponsored Content
Full Discussion: echo without newline
Top Forums Shell Programming and Scripting echo without newline Post 302703429 by Chubler_XL on Wednesday 19th of September 2012 06:11:48 PM
Old 09-19-2012
How about this in bash:

Code:
#!/bin/bash
COLS=0
[ -t 1 ] && COLS=$(tput cols)
 
function show_pct
{
   pct=$1
   [ $COLS -lt 10 ] && return
 
   if [ $pct -lt 0 ]
   then
       printf "\r%-*s\r" $((COLS-2))
       return
   fi
 
   if [ $pct -eq 0 ]
   then
       fill=""
       printf -v rest "%-*s" $((COLS-10))
   else
     printf -v fill "%-*s" $((pct*(COLS-10)/100))
     printf -v rest "%-*s" $((COLS-10-(pct*(COLS-10)/100)))
   fi
   printf "\r%4d%% [%s%s]" $pct "${fill// /=}" "${rest// /.}"
}
 
for((val=0;val<101;val++)) {
    show_pct $val
    sleep 0.05
}
show_pct -1

---------- Post updated at 08:11 AM ---------- Previous update was at 07:51 AM ----------

Replace last line of function with
Code:
 printf "\r       %s%s]\r%4d%% [%s" "$fill"  "${rest// /.}" $pct "${fill// /=}" >&2

To output to stderr and leave cursor at % complete position, however this outputs nearly twice as many characters for each percentage.

It's also worth "remembering" the last percentage displayed and not outputting anything if the percentage is the same.

Last edited by Chubler_XL; 09-19-2012 at 07:17 PM..
 

10 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

newline

I have an old file originally created in vi but read and saved by a word processor at some point. I have ^Ms and know how to substitute them for anything I wish but I still only have one long line when viewed in vi. So I suppose I need to substitute a newline for each ^M but I don't know the... (2 Replies)
Discussion started by: Gale Gorman
2 Replies

2. Shell Programming and Scripting

replace a newline (\n)

dear all: maybe i have a file like : 12 34 56 78 end how do write can i replace newline into NA : make the file inte : 12 NA 34 NA 56 78 END (3 Replies)
Discussion started by: jeter
3 Replies

3. UNIX for Dummies Questions & Answers

newline character

hi, I want to print the below lines "Message from bac logistics The Confirmation File has not been received." When i give like this in the code "Message from bac logistics\n The Confirmation File has not been received." It is giving only Message from bac logistics\n The... (9 Replies)
Discussion started by: trichyselva
9 Replies

4. UNIX for Dummies Questions & Answers

echo without newline character

hi, I have a for loop where in I write some file name to another file. I want to write all the filenames to another without any newlines. how can i avoid getting new lines with echo? Thanks, Srilaxmi (2 Replies)
Discussion started by: srilaxmi
2 Replies

5. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

6. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

7. UNIX for Dummies Questions & Answers

newline in echo

Hi all, I have a scripts in csh and whenI do echo command I want to add newline. I used to do it like this: #! /bin/csh echo "\n\n WHAT AREA DO YOU WANT:\n\n" echo -n " YOUR CHOISE : " set area=$< but since weupgrade the oracle to 10g it doesn't do the newline (he print the\n as a... (5 Replies)
Discussion started by: rikyer
5 Replies

8. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

9. Shell Programming and Scripting

Echo to file using SH without adding newline character

Hello! I am able to do this in bash, using: echo -ne HELLO > file.txt and then, 'HELLO' is written into file.txt without the newline character to be added in the end of the file. How is this possible to be done using sh instead of bash? If I try something similar is SH, then inside... (3 Replies)
Discussion started by: hakermania
3 Replies

10. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies
IMAGECOPYMERGE(3)							 1							 IMAGECOPYMERGE(3)

imagecopymerge - Copy and merge part of an image

SYNOPSIS
bool imagecopymerge (resource $dst_im, resource $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h, int $pct) DESCRIPTION
Copy a part of $src_im onto $dst_im starting at the x,y coordinates $src_x, $src_y with a width of $src_w and a height of $src_h. The portion defined will be copied onto the x,y coordinates, $dst_x and $dst_y. PARAMETERS
o $dst_im -Destination image link resource. o $src_im -Source image link resource. o $dst_x - x-coordinate of destination point. o $dst_y - y-coordinate of destination point. o $src_x - x-coordinate of source point. o $src_y - y-coordinate of source point. o $src_w -Source width. o $src_h -Source height. o $pct - The two images will be merged according to $pct which can range from 0 to 100. When $pct = 0, no action is taken, when 100 this function behaves identically to imagecopy(3) for pallete images, except for ignoring alpha components, while it implements alpha transparency for true colour images. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Merging two copies of the PHP.net logo with 75% transparency <?php // Create image instances $dest = imagecreatefromgif('php.gif'); $src = imagecreatefromgif('php.gif'); // Copy and merge imagecopymerge($dest, $src, 10, 10, 0, 0, 100, 47, 75); // Output and free from memory header('Content-Type: image/gif'); imagegif($dest); imagedestroy($dest); imagedestroy($src); ?> PHP Documentation Group IMAGECOPYMERGE(3)
All times are GMT -4. The time now is 06:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy