LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-05-2005, 05:49 AM   #1
xvalentinex
LQ Newbie
 
Registered: Dec 2005
Posts: 15

Rep: Reputation: 0
[SOLVED] Bash scripting alternating - / \


This should be a simple one for all you programming gurus

Kind of hard for me to explain and I'm sure there's a guide out there that tells how to do it, I just don't know what to search for (believe me I tried).

What I am looking to do is create that alternating dash mark that shows the script is working.

It sort of looks like this while working, except all the same line, with the last character appearing to be spinning.

Moving /dir1/file to /dir2/file... /
Moving /dir1/file to /dir2/file... -
Moving /dir1/file to /dir2/file... \
Moving /dir1/file to /dir2/file... /
Moving /dir1/file to /dir2/file... -
Moving /dir1/file to /dir2/file... \

Does this make any sense?

Thanks for any help,
-xvalentinex

Last edited by xvalentinex; 12-07-2005 at 01:56 PM.
 
Old 12-05-2005, 06:11 AM   #2
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
Is this ultimately similar to what you're trying to achieve? I know it doesn't answer your question but if somebody has done the work already no need to start again if you don't have to
 
Old 12-05-2005, 03:34 PM   #3
xvalentinex
LQ Newbie
 
Registered: Dec 2005
Posts: 15

Original Poster
Rep: Reputation: 0
Yeah sort of like that, but on a much simpler scale.

I took a look at the source hoping to grab some tidbits, but It looks like c and a very long source at that. I just need something really simple that shows the script is working.
 
Old 12-05-2005, 03:38 PM   #4
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,197

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
i think this is what you want:
http://www.linuxquestions.org/questi...hlight=spinner
hth
 
Old 12-06-2005, 01:15 AM   #5
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
Quote:
Originally Posted by schneidz
I didn't mean to copy the code, your example script was moving a file. I figured if you just wanted to pretty up mv a little then that's been done already
 
Old 12-06-2005, 08:39 PM   #6
xvalentinex
LQ Newbie
 
Registered: Dec 2005
Posts: 15

Original Poster
Rep: Reputation: 0
The spinner is perfect, and cs-cam that definately helps and simplifies while looking better too. To be more clear what I am trying to do is unrar some files and move them to a network server. The spinner is great since I am sending the rar output to /dev/null and the progress bar works for the move portion.

I'm still quite a newb at linux and especially scripting. Perhaps someone could shed some light on what I need to do to have the spinner going while the file is unraring.

Here is a snippet of what I have but it doesn't work.
Code:
#!/bin/bash
# Author: 
# Created 12.05.2005

# Spinner function
spinner() {
sleep 1
echo -ne "\b\\"
sleep 1
echo -ne "\b|"
sleep 1
echo -ne "\b/"
sleep 1
echo -ne "\b-"
}

# Getting files extracted to ./

for CDNUM1 in {CD,cd}1
do
    if [ -d $CDNUM1 ]
    then
        echo Now working on $CDNUM1
        CD1AVI=`rar vb ./$CDNUM1/*.rar`
        echo The file for CD1 is $CD1AVI
        echo -ne "-"
        while [ `rar e ./$CDNUM1/*.rar ./ > /dev/null` ]
        do
            spinner
        done
        echo Done extracting $CD1AVI
    fi
done

Last edited by xvalentinex; 12-06-2005 at 08:42 PM.
 
Old 12-07-2005, 07:12 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,312

Rep: Reputation: 175Reputation: 175
do the spinner as a function.
set it background save pid.
do processing and kill the spinner.
something like

Code:
spinner &
spinner_pid=$!
do_process
kill $spinner_pid
 
Old 12-07-2005, 07:20 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,312

Rep: Reputation: 175Reputation: 175
Code:
#!/bin/ksh

# Spinner function
spinner() {
  while : ;do

    printf "\b\\"
    printf "\b|"
    printf "\b/"
    printf "\b-"
  done
}

echo hello
spinner &
sleep 5
kill $!
though of course if your process outputs it will
foul up the spinner.
 
Old 12-07-2005, 07:28 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,312

Rep: Reputation: 175Reputation: 175
also you may need an EXIT trap in case you end up with a spinner
lying around after a break.
 
Old 12-07-2005, 01:56 PM   #10
xvalentinex
LQ Newbie
 
Registered: Dec 2005
Posts: 15

Original Poster
Rep: Reputation: 0
Works great, thanks guys
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help bash scripting sh4d0w13 Linux - Newbie 5 08-15-2005 03:02 AM
need help with bash scripting rich2oo1 Programming 2 12-17-2003 01:50 PM
Bash scripting SWAT Linux - Newbie 2 11-11-2003 04:21 AM
About bash scripting pazvant Programming 3 10-20-2003 12:12 PM
HELP with BASH scripting atwah Linux - Newbie 6 09-09-2003 02:10 AM


All times are GMT -5. The time now is 08:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration