Prev: OMG!...cant believe i found this on the usenet!!
Next: MAKE UPTO $5000 PER MONTH! $2000 IN FIRST 20 DAYS!
From: Paul Branon on 19 Jun 2010 13:14 I've found some code that makes a cursor spin around. It appears to me that the author is globbing/patternmatching his way through the cursor spin states. But he doesn't comment what he's done. There are a couple of clever things, secondly is the printf substitution that he's done. But in order to make that work he's had to do globbing involving #? (what's # in bash globbing? and specifically what does it do here?) and what's % specifically before the three single character wildcards? Basically, if anybody would be good enough to talk me through what's going on here I'd be immensely grateful. #!/bin/bash printf "Processing |" rotate='|/-\' while [ 0 ] do rotate="${rotate#?}${rotate%???}" printf '\b%.1s' "$rotate" sleep 1 done
From: David W. Hodgins on 19 Jun 2010 13:50 On Sat, 19 Jun 2010 13:14:01 -0400, Paul Branon <paulbranon(a)googlemail.com> wrote: > Basically, if anybody would be good enough to talk me through what's > going on here I'd be immensely grateful. > rotate="${rotate#?}${rotate%???}" ${rotate#?} strips off the first character. ${rotate%???} gives you just the first character Note that the variable rotate on the right side gets expanded in both places, before it gets reassigned. The result is the first character in the string gets moved to the end. See "man bash" under the "Parameter Expansion" heading. > printf '\b%.1s' "$rotate" The \b prints a backspace The %.1s specifies string format, with a precision of 1 (for a string, the precision is the max length), effectively printing the first character. See "man 3 printf", under the "The precision" heading. Regards, Dave Hodgins -- Change nomail.afraid.org to ody.ca to reply by email. (nomail.afraid.org has been set up specifically for use in usenet. Feel free to use it yourself.)
From: Bill Marcum on 19 Jun 2010 14:16 On 2010-06-19, Paul Branon <paulbranon(a)googlemail.com> wrote: > I've found some code that makes a cursor spin around. > > It appears to me that the author is globbing/patternmatching his way > through the cursor spin states. But he doesn't comment what he's done. > There are a couple of clever things, secondly is the printf > substitution that he's done. But in order to make that work he's had > to do globbing involving #? > (what's # in bash globbing? and specifically what does it do here?) > and what's % specifically before the three single character > wildcards? > ${variable#pattern} is similar to "echo $variable |sed 's/^pattern//'" but the pattern matching isn't "greedy" unless you double the #. Likewise ${variable%pattern} is similar to "echo $variable | sed 's/pattern$//'" This is a feature of POSIX shells, not just bash. -- If Patrick Henry thought that taxation without representation was bad, he should see how bad it is with representation.
From: Michael Paoli on 25 Jun 2010 00:22 On Jun 19, 10:14 am, Paul Branon <paulbranon(a)googlemail.com> wrote: > I've found some code that makes a cursor spin around. > > #!/bin/bash > printf "Processing |" > rotate='|/-\' > > while [ 0 ] > do > rotate="${rotate#?}${rotate%???}" > printf '\b%.1s' "$rotate" > sleep 1 > done Would be good to check that TERM isn't a hardcopy terminal, etc. Also would be good to put a sleep(1) in the loop to reduce wasted CPU and I/O consumption. #!/bin/sh trap 'echo; exit 0' 1 2 3 15 if ! >>/dev/null 2>&1 tput longname || tput hc || { tput os && ! tput eo } then # unknown, hardcopy, or overstrikes and can't erase with blank while : do printf . sleep 10 done elif tput os; then # not hardcopy, does overstries, but can erase with blank while : do ( for c in \| / - \\\\ do printf -- " \010$c\010" sleep 1 done ) done else # not hardcopy, TERM doesn't do overstrikes while : do ( for c in \| / - \\\\ do printf -- "$c\010" sleep 1 done ) done fi references/excerpts: tput(1) terminfo(5) sh(1) erase_overstrike eo eo can erase over- strikes with a blank hard_copy hc hc hardcopy terminal over_strike os os terminal can over- strike
From: Barry Margolin on 25 Jun 2010 21:48
In article <85c9976e-75b6-4aff-8931-ba414712a5de(a)y11g2000yqm.googlegroups.com>, Michael Paoli <michael1cat(a)yahoo.com> wrote: > On Jun 19, 10:14�am, Paul Branon <paulbranon(a)googlemail.com> wrote: > > �I've found some code that makes a cursor spin around. > > > > #!/bin/bash > > printf "Processing |" > > rotate='|/-\' > > > > while [ 0 ] > > do > > � � rotate="${rotate#?}${rotate%???}" > > � � printf '\b%.1s' "$rotate" > > � � sleep 1 > > done > > Would be good to check that TERM isn't a hardcopy terminal, etc. > Also would be good to put a sleep(1) in the loop to reduce wasted > CPU and I/O consumption. There *is* a sleep in the loop. I can't recall the last time I saw a hardcopy terminal used interactively. It must be at least 15 years. -- Barry Margolin, barmar(a)alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group *** |