From: superpollo on 17 Jun 2010 08:24 John Kelly ha scritto: > 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. or python: [~/superpollo]$ N=20 [~/superpollo]$ python -c 'print "="*'$N ==================== [~/superpollo]$
From: Ed Morton on 17 Jun 2010 08:41 On 6/17/2010 3:35 AM, 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 $ printf "%020s\n" | tr '0' '=' ==================== $ n=10 $ printf "%0""$n""s\n" | tr '0' '=' ========== > Is there a better way and just with bash build-ins? Don't know if printf or tr are bash built-ins. Don't know why you'd care though. Ed.
From: Ed Morton on 17 Jun 2010 08:59 On 6/17/2010 7:41 AM, Ed Morton wrote: > On 6/17/2010 3:35 AM, 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 > > $ printf "%020s\n" | tr '0' '=' > ==================== > > $ n=10 > $ printf "%0""$n""s\n" | tr '0' '=' > ========== > >> Is there a better way and just with bash build-ins? > > Don't know if printf or tr are bash built-ins. Don't know why you'd care > though. ....nor do I know why I thought "0" was a better char for replacement than " ": $ printf "%20s\n" | tr ' ' '=' ==================== $ n=10 $ printf '%'"$n"'s\n' | tr ' ' '=' ========== Sigh.... Ed.
From: pk on 17 Jun 2010 09:03 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? With bash and builtins: printf -v string "%30s" " " echo "${string// /=}"
From: John Kelly on 17 Jun 2010 09:53
On Thu, 17 Jun 2010 07:59:31 -0500, Ed Morton <mortonspam(a)gmail.com> wrote: >> $ printf "%020s\n" | tr '0' '=' >> ==================== >...nor do I know why I thought "0" was a better char for replacement than " ": > >$ printf "%20s\n" | tr ' ' '=' >==================== Both produce a string of blanks. In the first example, you would need a %d format specifier to get leading zeros. -- Web mail, POP3, and SMTP http://www.beewyz.com/freeaccounts.php |