DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

Bash Progress Wheel

Snippets Manager user avatar by
Snippets Manager
·
Aug. 31, 06 · · Code Snippet
Like (0)
Save
Tweet
719 Views

Join the DZone community and get the full member experience.

Join For Free
// print a progress wheel


#!/bin/bash
#
# anim.sh
# print a progress wheel while test_pad returns 0
#
# $ANIM  : wheel
# $PAD   : on what $ANIM moves
# $SLEEP : timer
#
# Author : Nicolas Marciniak 



function test_pad()
{
        return 0
}

function reverse()
{
        string=$1
        len=$(echo -n $string | wc -c)
        while test $len -gt 0
        do
                rev=$rev$(echo $string | cut -c $len)
                len=$(( len - 1 ))
        done
        echo $rev
}

ANIM="//--\\||"
PAD="                                                                  "
SLEEP="0.1"

ANIM_L="$(reverse $ANIM)"
PAD_LN=${#PAD}
ANIM_LN=${#ANIM}
u=0; re=0; l=0

while test_pad; do
        if [ $re -eq 1 ]; then L=$ANIM_L; else L=$ANIM; fi
        if [ $re -eq 1 ]; then p=$(( $PAD_LN - $u )); else p=$u; fi
        echo -ne "${PAD:0:$p} ${L:$l:1} ${PAD:$p:$PAD_LN} \r"
        if [ $u -eq $PAD_LN ]; then u=0; if [ $re -eq 1 ]; then re=0; else re=1; fi; fi
        u=$(( u + 1 )); l=$(( l + 1 ))
        if [ $l -eq $ANIM_LN ]; then l=0; fi
        sleep $SLEEP
done
exit 0


Bash (Unix shell)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Your Old Laptop Is Your New Database Server
  • An Overview of 3 Java Embedded Databases
  • The Most Popular Kubernetes Alternatives and Competitors
  • Is Java Still Relevant?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo