Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a hint:</p> <pre><code>echo ${string:0:3} echo ${#string} </code></pre> <p><strong>Edit (2011-02-11):</strong></p> <p>Here's my solution. I added some additional parameters with defaults.</p> <pre><code>rotate-string () { local s=${1:-1} p=${2:--1} w=${3:-8} c=${4:-0} r l printf -vr '%0*d' $w 0 # save $w zeros in $r r=${r//0/$c}$s # change the zeros to the character in $c, append the string r=${r: -w} # save the last $w characters of $r l=${r: -p%w} # get the last part of $r ($p mod %w characters) echo "$l${r::w-${#l}}" # output the Last part on the Left and the Right part which starts at the beginning and goes for ($w minus the_length_of_the_Left_part) characters } </code></pre> <p>usage: <code>rotate-string string positions-to-rotate width fill-character</code></p> <p>example: <code>rotate-string abc -4 9 =</code></p> <p>result: <code>==abc====</code></p> <p>Arguments can be omitted starting from the end and these defaults will be used:</p> <ul> <li>fill-character: "0"</li> <li>width: 8</li> <li>positions-to-rotate: -1</li> <li>string: "1"</li> </ul> <p>More examples:</p> <pre><code>$ rotate-string 00000010 $ rotate-string 123 4 01230000 </code></pre> <p>Fun stuff:</p> <pre><code>$ for i in {126..6}; do printf '%s\r' "$(rotate-string Dennis $i 20 .)"; sleep .05; done; printf '\n' $ while true; do for i in {10..1} {1..10}; do printf '%s\r' "$(rotate-string : $i 10 .)"; sleep .1; done; done $ while true; do for i in {40..2} {2..40}; do printf '%s\r' "$(rotate-string '/\' $i 40 '_')"; sleep .02; done; done $ d=0; while true; do for i in {1..10} {10..1}; do printf '%s\r' "$(rotate-string $d $i 10 '_')"; sleep .02; done; ((d=++d%10)); done $ d=0; while true; do for i in {1..10}; do printf '%s\r' "$(rotate-string $d $i 10 '_')"; sleep .2; ((d=++d%10)); done; done $ shape='▁▂▃▄▅▆▇█▇▆▅▄▃▂▁'; while true; do for ((i=1; i&lt;=COLUMNS; i++)); do printf '%s\r' "$(rotate-string "$shape" $i $COLUMNS ' ')"; done; done </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload