Re: bash question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Miner, Jonathan W (CSC) (US SSA) wrote:
> 
> 
> -----Original Message-----
> From:	fedora-list-bounces@xxxxxxxxxx on behalf of Dario Lesca
> Sent:	Wed 10/31/2007 09:12 AM
> To:	Fedora Project List
> Cc:	
> Subject:	bash question
> 
> In this shell script:
> 
>> #!/bin/bash
>> i=0
>>
>> printf "a a a\nb b b\nc c c\n" |
>> while read x
>> do
>>         i=$[i+1]
>>         echo "$x: ($i)"
>> done
>>
>> echo $i
> 
> -------------------------------
> 
> By pipe'ing the commands together, you cause the while loop to be executed in a subshell. Change your script to be:
> 
> #!/bin/bash
> i=0
> 
> while read x
> do
>          i=$[i+1]
>          echo "$x: ($i)"
> done << _EOF_
> a a a
> b b b
> c c c
> _EOF_
> 
> echo $i
> 
> 
> 

Or:

#!/bin/bash
printf "a a a\nb b b\nc c c\n" | {
i=0
while read x
do
    i=$[i+1]
    echo "$x: ($i)"
done
echo $i
}



-- 
Sjoerd Mullender

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux