Reading a variable line by line with while loop
Ray Parrish
crp at cmc.net
Tue Dec 1 15:39:05 UTC 2009
Smoot Carl-Mitchell wrote:
> On Tue, 2009-12-01 at 06:57 -0800, Ray Parrish wrote:
>
>> Ray Parrish wrote:
>>
>> Hello again,
>>
>> OK, I understand that the | is causing a sub shell to execute for the
>> echo command, so the variable $History even 'though declared globally,
>> is local to the loop with the pipe, and therefore not available after
>> the loop exits.
>>
>>
>
> Right. subshells do not pass their environment back to their parent.
> The read command is pretty inefficient. You might want to learn sed.
> It is well suited to this particular task. Something like:
>
> History=`sed 's/ /__/g' ~/.bash_history`
>
> The substitution replaces all spaces in the Bash history with __.
> Output is interpolated inline and assigned to the History variable.
>
Thank you! That worked great! Now I wonder is there is another great sed
command that will remove redundancy in the bash history, so no command
line is repeated in the final results in the $History variable?
I don't mean to get you to do my programming for me, and I will begin
studying the sed manual right after I send this to see if I can figure
it out myself. I just thought I'd pick your brain a bit more. 8-)
Later, Ray Parrish
--
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com
More information about the ubuntu-users
mailing list