![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Repeat last entered command ? | vilius | Shell Programming and Scripting | 5 | 09-25-2007 03:15 AM |
| to copy and repeat | falcondown01 | Shell Programming and Scripting | 4 | 09-07-2007 05:15 PM |
| Repeat Commands | dereckbc | UNIX for Dummies Questions & Answers | 6 | 01-04-2005 08:15 AM |
| Keyboard repeat speed | tecss | UNIX for Advanced & Expert Users | 1 | 05-17-2004 06:05 PM |
| any idea to repeat a action in VI | myelvis | UNIX for Dummies Questions & Answers | 6 | 11-26-2003 03:21 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
repeat character with printf
It's all in the subject. I try to figure out how to repeat a character a number of time with printf.
For example to draw a line in a script output. Thks |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
I didn't know repeating characters was printf's speciality
If you don't mind using perl, this should be ok: Code:
$ perl -e 'print "-" x 25,"\n"' ------------------------- |
|
#3
|
|||
|
|||
|
Thanks. I was hoping to find some pure bash solution like padding with a custom character like in PHP
Code:
printf("%'#10s\n", '');
|
|
#4
|
||||
|
||||
|
ksh93/bash:
Code:
for i in {1..100};do printf "%s" "#";done;printf "\n"
Code:
repeat 100 printf "#";print ksh93/zsh and bash: Code:
ch="$(printf "%100s" "")"
printf "%s\n" "${ch// /#}"
bash3 Code:
printf -vch "%100s" ""
printf "%s\n" "${ch// /#}"
Code:
print "${$(printf "%100s" "")// /#}"
Last edited by radoulov; 12-13-2007 at 04:13 AM. |
|
#5
|
|||
|
|||
|
I like that one. The best I could come up with was this:
Code:
LINE="########################################################"
echo ${LINE,0,15}
|
|
#6
|
||||
|
||||
|
Sorry,
in zsh it could be just like this Code:
print ${(l:100::#:)}
|
|
#7
|
||||
|
||||
|
I have never found a real great ksh method that doesn't resort to the extentions of ksh93. But if I need this, I use a function...
Code:
$ function fill { typeset i=$1 c="$2" s="" ; while ((i)) ; do ((i=i-1)) ; s="$s$c" ; done ; echo "$s" ; }
$ s=$(fill 15 \*)
$ echo "$s"
***************
$
|
||||
| Google The UNIX and Linux Forums |