[clug] Rosetta code: bash/bourne shell 'loops' example
hal.ashburner at gmail.com
Sun Mar 21 04:04:53 MDT 2010
On 03/21/2010 08:55 PM, steve jenkin wrote:
> Peter Barker wrote on 21/03/10 8:01 PM:
>> On Sun, 21 Mar 2010, steve jenkin wrote:
>> I think I prefer this - what I think to be pretty idiomatic:
>> pbarker at eccles:~$ for i in `seq 1 5`; do for j in `seq 1 $i`; do echo -n
>> '*'; done; echo; done
>> pbarker at eccles:~$
>> Or did I miss something?
> I wasn't aware of the 'seq' command/builtin
> [hence my "yes|head|tr -d '\n' "]
> The Rosetta people made a distinction between "Unix Shell" and "Unix
> pipeline", which I find a little arbitrary and confusing...
> Didn't look further to find how they drew the line.
> I like your one-liner better :-)
So do I compared to the following bash-ism.
$ for ((i=1; $i <=5; i=$i+1));do for ((j=1; $j <=$i; j=$j+1)); do
printf "*"; done; printf "\n"; done
But it might save a fork or two.
More information about the linux