From: Marc Muehlfeld on
Hello,

how can I print n equal signs in a shell script, without using a for loop, like

for i in `seq 1 20` ; do
echo -n "="
done

Is there a better way and just with bash build-ins?


Regards,
Marc
From: Chris F.A. Johnson on
On 2010-06-17, Marc Muehlfeld wrote: > Hello, > > how can I print n
equal signs in a shell script, without using a for loop, like > > for
i in `seq 1 20` ; do > echo -n "=" > done > > Is there a better way
and just with bash build-ins?

eq===========================================================================================
num=20
printf "%.${num}s\n" "$eq"

Or:

printf "%s\n" "${eq:0:$num}" ## not portable

--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)

From: Marc Muehlfeld on
Am 17.06.2010 11:19, schrieb Chris F.A. Johnson:
> eq===========================================================================================
> num=20
> printf "%.${num}s\n" "$eq"
>
> Or:
>
> printf "%s\n" "${eq:0:$num}" ## not portable


But this both command require the definition of a looooong line of "=" and I
don't know if I need 5, 20, 100, 5000,...

From: Chris F.A. Johnson on
On 2010-06-17, Marc Muehlfeld wrote:
> Am 17.06.2010 11:19, schrieb Chris F.A. Johnson:
>> eq===========================================================================================
>> num=20
>> printf "%.${num}s\n" "$eq"
>>
>> Or:
>>
>> printf "%s\n" "${eq:0:$num}" ## not portable
>
>
> But this both command require the definition of a looooong line of "=" and I
> don't know if I need 5, 20, 100, 5000,...

eq========================
num=999 ## adjust to taste

while [ ${#eq} -lt $num ]
do
eq=$eq$eq$eq
done


--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)

From: John Kelly on
On Thu, 17 Jun 2010 11:34:18 +0200, Marc Muehlfeld
<marc.muehlfeld(a)web.de> wrote:

>Am 17.06.2010 11:19, schrieb Chris F.A. Johnson:
>> eq===========================================================================================
>> num=20
>> printf "%.${num}s\n" "$eq"
>>
>> Or:
>>
>> printf "%s\n" "${eq:0:$num}" ## not portable
>
>
>But this both command require the definition of a looooong line of "=" and I
>don't know if I need 5, 20, 100, 5000,...

Sounds like you want a string repeat operator or function. I can't
think of any such feature in bash. Perl may have something like that.


--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php