The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SH: two variables in for loop marcpascual Shell Programming and Scripting 20 07-07-2009 07:23 AM
Is there a better way I could have run this loop. (For loop with two variables) DeCoTwc Shell Programming and Scripting 2 03-27-2009 02:07 AM
foreach loop + 2 variables JamesGoh Shell Programming and Scripting 3 06-04-2008 04:36 AM
While loop with Multiple variables amit1_x Shell Programming and Scripting 4 04-02-2008 07:35 AM
using variables outside a while loop Tornado Shell Programming and Scripting 2 02-09-2007 01:26 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-03-2009
Starcast Starcast is offline
Registered User
  
 

Join Date: Jan 2009
Location: Minneapolis, MN
Posts: 13
Help with proper loop and variables

I have written a Bash Script that captures video via the Linux application DVgrab. When run my script prompts the terminal user to enter all the necessary information for the capture, save location, file name, file type capture duration etc...

These are all in the form of


Code:
#!/bin/bash
echo -n "Enter the duration for the capture: "
read duration

dvgrab -loacation /home/somefolder -filetype avi -duration $duration

This works great for me, my problem is that I want the script to run in such a way that once it finishes a capture it returns to the beginning of the script and asks for variables again to start another capture.

My first attempt was simply to add


Code:
#!/bin/bash
time=5
until [ time = 1 ]
do 
 -my whole script-
done

And now you will see that I don't really know what I am doing or how to talk about it... I am just learning this stuff (I can only imagine there is a more correct 'repeat forever'?)

My problem here is that once the script goes back to the 'do' line it already 'knows' all the variables and just starts the same dvgrab capture again...

Is there a way to 'reset' all my entered variables? or perhaps some other method of looping that is more appropriate?

Thanks
-Starcast
  #2 (permalink)  
Old 04-03-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,346
Something like this, the loop stops if the user enters an empty string:


Code:
#!/bin/bash

stop=1

while [ $stop -gt 0 ]
do
  echo -n "Enter the duration for the capture: "
  read duration

  case "$duration" in
    "") stop=0 ;;
     *) dvgrab -loacation /home/somefolder -filetype avi -duration $duration ;;
  esac
done

Regards
  #3 (permalink)  
Old 04-07-2009
Starcast Starcast is offline
Registered User
  
 

Join Date: Jan 2009
Location: Minneapolis, MN
Posts: 13
Hmm, I think I wasn't clear in what I'm trying to achieve. My problem is not related to stopping the script, but in getting the script to repeat.

There are 4 questions that the script prompts the user to enter as variables, and what I want to script to do is essentially start over once it's finished. So that after one tape ends, the script is already waiting for the information (a new instance of each of the variables) for the next tape to be entered...

As it stands I achieve this by simply typing in the command to run the script again after each tape finishes, but I want to eliminate this extra step.

Thanks for your help
-Starcast
  #4 (permalink)  
Old 04-16-2009
Starcast Starcast is offline
Registered User
  
 

Join Date: Jan 2009
Location: Minneapolis, MN
Posts: 13
Read error: Resource Unavailable

Franklin52: Your Loop suggestion works perfectly for what I want, thanks...

But I've discovered my problem is not in my looping instructions, but in a -read- error, namely one that looks like this:

./test5: line 14: read: read error: 0: Resource temporarily unavailable
(line 14 is the last line in the code below)

When I run this code:


Code:
#!/bin/bash

function record
{
dvgrab --format raw --duration smpte=$tape_length:00 --noavc --size 0 tapename.dv
}

tape_lenght=00:00:10

record

echo -n "Test -read- command:"
read null2

My actual script is much larger (400 lines, I can post it if that might help), but I've narrowed my problem to this error. As far as I can tell executing DVgrab does something that makes -read- "temporarily unavailable" and every instance of -read- after DVgrab has this error

In my larger script this has the effect of continuously applying the same variable entries (previously entered via -read-) and therefore continuously records the same clip length over and over

Any ideas why this is happening or what a workaround might be would be greatly appreciated, in the above test script I thought maybe putting DVgrab in a function might help, but it seems to have had no effect...

Thanks
-Starcast
  #5 (permalink)  
Old 04-17-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
how 'bout saving and restoring the stty:

Code:
#!/bin/bash

function record
{
dvgrab --format raw --duration smpte=$tape_length:00 --noavc --size 0 tapename.dv
}

tape_lenght=00:00:10

_STTY=$(stty -g)
record
stty "$_STTY"

echo -n "Test -read- command:"
read null2

  #6 (permalink)  
Old 04-18-2009
Starcast Starcast is offline
Registered User
  
 

Join Date: Jan 2009
Location: Minneapolis, MN
Posts: 13
Same result

Thanks for the suggestion, but after inserting those two lines I am still getting the same error message...

Any other ideas?

Thanks,
-Starcast
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0