Re: For loop prints two $values instead of one
On Tue, Jan 07, 2014 at 12:45:42AM +0200, DanielB wrote: > declare -a array=( 'sf052' 'to060' 'pw' 'qb099' 'pw22' 'wp039' 'wx12' > 'wx11' )for subD in "${array[@]}"; do > echo $subDdone > > output: > > sf052 > to060 > pw > qb099 pw22 > wp039 wx12 > wx11 I can only guess that your terminal is in some weird state, and/or your IFS variable has been set to something bizarre. The hypothesis about your terminal being in a weird state is somewhat strengthened by the mangling that was done in your email. If you properly quote "$subD" it will avoid any issues with IFS: for subD in "${array[@]}"; do echo "$subD" done Apart from the mangled formatting and the missing quotes, there's nothing wrong with your code. As for the terminal, you can try running the "reset" command, but in the most spectacular cases, it's often necessary to close the terminal window and open a new one (assuming a terminal emulator), or power the terminal off and back on (assuming a physical ASCII terminal).
Re: Parameter Substitution Causing Memory Leak
On 1/7/14, 2:27 AM, toddbst...@gmail.com wrote: > Repeat-By: > These can all be demonstrated by running a script consisting of an > infinite loop which repeatedly executes any command utilizing any of the > above examples. Like this: > > #!/bin/bash > > while :; do > echo ${variable/pattern} > done > > The resident memory size will continually grow. This occurs on both > CentOS 6.5 (bash 4.1.2) and Fedora 20 (bash 4.2.45). Have you run any of these through valgrind? I ran a few, and it did not report any leaks, at least on bash-4.3-rc1. The increase in memory size is probably from malloc getting memory from the kernel but not releasing it back to the kernel after bash calls free (giving memory back to the kernel is harder than you think). Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: Parameter Substitution Causing Memory Leak
These bugs result in gradual slowdown of indefinitely-running scripts which rely on parameter substitution (rather than forking sed or awk) for speed and efficiency. Forgive me if I used the wrong terminology, but whether these bugs are considered honest-to-goodness "memory leaks" by valgrind seems unimportant. Are you saying these bugs have been fixed, and that they no longer exist in bash 4.3? On Tue, Jan 7, 2014 at 11:12 AM, Chet Ramey wrote: > On 1/7/14, 2:27 AM, toddbst...@gmail.com wrote: > > > Repeat-By: > > These can all be demonstrated by running a script consisting of an > infinite loop which repeatedly executes any command utilizing any of the > above examples. Like this: > > > > #!/bin/bash > > > > while :; do > > echo ${variable/pattern} > > done > > > > The resident memory size will continually grow. This occurs on > both CentOS 6.5 (bash 4.1.2) and Fedora 20 (bash 4.2.45). > > Have you run any of these through valgrind? I ran a few, and it did not > report any leaks, at least on bash-4.3-rc1. The increase in memory size is > probably from malloc getting memory from the kernel but not releasing it > back to the kernel after bash calls free (giving memory back to the kernel > is harder than you think). > > Chet > -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > ``Ars longa, vita brevis'' - Hippocrates > Chet Ramey, ITS, CWRUc...@case.edu > http://cnswww.cns.cwru.edu/~chet/ >
Re: Parameter Substitution Causing Memory Leak
On 01/07/2014 12:18, Todd B. Stein wrote: These bugs result in gradual slowdown of indefinitely-running scripts which rely on parameter substitution (rather than forking sed or awk) for speed and efficiency. Forgive me if I used the wrong terminology, but whether these bugs are considered honest-to-goodness "memory leaks" by valgrind seems unimportant. google-perftools is able to help analyze such problems. It can produce memory reports in certain intervals of the program lifetime, and they graphically show who owns how much memory at particular times. In a nutshell, the run is done like this: HEAPPROFILE=google-profile-pid$$ LD_PRELOAD=/usr/lib/libtcmalloc.so $* Yuri
Re: Parameter Substitution Causing Memory Leak
On 1/7/14, 3:18 PM, Todd B. Stein wrote: > These bugs result in gradual slowdown of indefinitely-running scripts which > rely on parameter substitution (rather than forking sed or awk) for speed > and efficiency. Forgive me if I used the wrong terminology, but whether > these bugs are considered honest-to-goodness "memory leaks" by valgrind > seems unimportant. > > Are you saying these bugs have been fixed, and that they no longer exist in > bash 4.3? If they show up on bash-4.2, but not when using bash-4.3, then I guess they no longer exist. I did find a case where valgrind reported memory leaks on bash-4.2 but not bash-4.3, so I will assume that they have been fixed. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
print float number
Hi, How can I print the 0.05, 0.10 ... 1.0 out, with the step of 0.05 Thanks ahead for your suggestions,
Re: print float number
Hi lina, lina wrote: > How can I print the 0.05, 0.10 ... 1.0 out, with the step of 0.05 > > Thanks ahead for your suggestions, First please do not hijack threads. You replied to Chris Down's message responding to DanielB about "For loop prints two $values instead of one" and then changed the subject but your message isn't about anything to do with that thread. If you want to start a new thread like you did here please compose a new message. Please don't reply to an existing thread to start a new conversation. Second is that this is simply a question and not a bug report. Questions should go to the help-b...@gnu.org mailing list. > How can I print the 0.05, 0.10 ... 1.0 out, with the step of 0.05 As to your question there are many ways to solve the problem. I would be inclined to use the GNU seq command. $ seq 0.05 0.05 1.0 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 However seq is somewhat of a troubled command. It does math with floating point and sometimes suffers from the same problems as anything that does compter based floating point math with various approximation and rounding errors. You must be careful concerning it or odd errors will occur. A related question about for loops in bash is discussed in this FAQ entry. It isn't exactly your case but you might be interested in reading about the examples it provides. http://mywiki.wooledge.org/BashFAQ/018 I doubt just printing out these numbers were really your question. If you wrote a message to help-b...@gnu.org and described your task in more detail there are many people who would be happy to help you use bash effectively. Bob