LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 10-20-2011, 04:54 PM   #1
TwinReverb
Member
 
Registered: Sep 2008
Location: Misawa AB, Japan
Distribution: Slackware
Posts: 191
Blog Entries: 2

Rep: Reputation: 40
Bash Loop Scripting question


Hey all, I have a question for learning purposes. I have a live band DVD that I have ripped into multiple VOB files per song/chapter on the DVD. I would like to cut these to ogg audio. So far I was going to do this:

Code:
for i in track*.vob; do mplayer -ao pcm:file=$i.wav -vo null $i && oggenc -q9 $i.wav && rm $i.wav
This uses mplayer to cut the raw audio to a wav file and then it encodes them as ogg and deletes them. However, what if I wanted to do it so that if mplayer exits successfully, then it cuts a child process to do the encoding and deleting on its own while it goes on to the next file? My question is really how to cut child processes in this environment properly. I was thinking about:

Code:
for i in track*.vob; do mplayer -ao pcm:file=$i.wav -vo null $i && (oggenc -q9 $i.wav && rm $i.wav) &; done
But the problem here is that I want the entire oggenc/rm part to be its own child process (i.e. rm waits until oggenc successfully finishes), and the child process itself to also only launch if mplayer exits status 0 (successful). Anyone have some insight on how to do this?
 
Old 10-20-2011, 08:44 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If(!) I understand the qn correctly
Code:
for i in track*.vob
do
    mplayer -ao pcm:file=$i.wav -vo null $i
    if [[ $? -eq 0 ]]
    then 
        (oggenc -q9 $i.wav && rm $i.wav) &
    else
        echo "mplayer failed $? on $i "
        exit 1
    fi
done
 
Old 10-21-2011, 05:24 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Just one small comment in addition. Always quote your variable expansions, to protect them from word-splitting and other processing of reserved-characters.

http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes
 
1 members found this post helpful.
  


Reply



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
[SOLVED] Bash Scripting (until loop) cryingthug Programming 10 06-30-2010 09:30 PM
Until loop in bash shell scripting help computergeek7 Programming 6 03-01-2010 11:34 PM
Need help in bash scripting in while loop manya Programming 2 11-25-2009 09:51 AM
bash scripting problem with nested if statements in while loop error xskycamefalling Programming 4 05-11-2009 03:14 PM
bash scripting: loop over a file, replacing two decimal numbers frankie_DJ Programming 2 04-30-2007 04:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:14 PM.

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
Open Source Consulting | Domain Registration