Re: Output n equal signs from a script
- From: Janis Papanagnou <janis_papanagnou@xxxxxxxxxxx>
- Date: Thu, 17 Jun 2010 18:51:25 +0200
pk wrote:
Janis Papanagnou wrote:
pk wrote:
Marc Muehlfeld wrote:This fails for the corner case n=0; which produces 1 (instead of 0)
Hello,With bash and builtins:
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?
printf -v string "%30s" " "
echo "${string// /=}"
characters. Instead use
printf -v string "%30s" ""
True, thanks.
Also, it's easy to be portable; use
string=$( printf "%30s" "" )
Modern shells (I think ksh optimizes such types of calls) may not even
use a subshell for that expression.
Well yes, but that's only one part of it; the other key element is
${string// /=} which is also nonstandard; given this, and also that the OP
explicitly mentioned bash, I thought I could just as well use other
bashisms.
But consider that the $(...) variant will run on other modern shells as well
while the printf -v doesn't.
YMMV, but I consider a solution that runs on any modern shell to be preferable
to one that uses bash'isms unnecessarily.
Janis
.
- Follow-Ups:
- Re: Output n equal signs from a script
- From: John Kelly
- Re: Output n equal signs from a script
- References:
- Output n equal signs from a script
- From: Marc Muehlfeld
- Re: Output n equal signs from a script
- From: pk
- Re: Output n equal signs from a script
- From: Janis Papanagnou
- Re: Output n equal signs from a script
- From: pk
- Output n equal signs from a script
- Prev by Date: Re: Output n equal signs from a script
- Next by Date: Re: Output n equal signs from a script
- Previous by thread: Re: Output n equal signs from a script
- Next by thread: Re: Output n equal signs from a script
- Index(es):
Relevant Pages
|