Register
It is currently Thu Oct 02, 2014 2:25 am

Taking arguments


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Tue Oct 31, 2006 9:07 am   

Joined: Mon Apr 24, 2006 2:39 pm
Posts: 30
Location: Villahermosa
Hi I want to know how can I create a simple script that will take arguments. An example of what I mean is by doing a static wrapper that will replace something like this:
Code:
$ mencoder <filename.avi> -ovc lavc -oac lavc -ffourcc DX50 -o <output.avi>


to this:
Code:
$ lessvideo <filename.avi> <output.avi>


My guess is that I will need to generate an array wich catch the input videos and somehow take the last one as the output. Thanks in advance.


Top
 Profile WWW ICQ YIM  
 PostPosted: Tue Oct 31, 2006 12:46 pm   

Joined: Fri Oct 14, 2005 9:30 am
Posts: 61
This should work (havent tested it as my linux box is broke).
Code:
#!/bin/bash
mencoder $1 -ovc lavc -oac lavc -ffourcc DX50 -o $2

$1 and $2 are the first two arguments you give the script ($0 gives script name).
You can carry on going up to $9.

so how this corresponds to how you run the script is:
Code:
lessvideo <filename.avi (this will be variable $1)> <output.avi (this will be variable $2)>

HTH,
Rob


Top
 Profile WWW  
 PostPosted: Tue Oct 31, 2006 5:27 pm   

Joined: Mon Apr 24, 2006 2:39 pm
Posts: 30
Location: Villahermosa
ok this solves it but I was more interested when there is a sequense of arguments such as when you merge a movie, movie-1.mpg movie-2.mpg movie3.mpg and then the last is movie-complete.mpeg.

This will make the script take all the arguments -1 which will be the output file. I guess I never expressed this on my first post.


Top
 Profile WWW ICQ YIM  
 PostPosted: Mon Nov 06, 2006 1:27 pm   
User avatar

Joined: Mon Jul 03, 2006 8:58 pm
Posts: 52
Location: Rochester, NY
In that case you can use a for loop to grab each argument regardless of how many there are. You'll probably want to hold on to them until you've read them all so you know which is the last one, but aside from that it's fairly straight-forward...

This example draws upon jbsnake's excellent previous post

Code:
#Example input: lessvideo movie1.mpg movie2.mpg movie3.mpg finalmovie.mpg
#
#!/bin/bash

declare -a inputargs; # declare the argument array
declare -i pos;          # declare an integer index

# grab all the arguments from the command line
for arg; do inputargs[pos++]=$arg; done

mycmd="mencoder ";

# now loop through the args and insert all but the last one into your command
argnum=${#inputargs[*]}
for (( pos=0; $pos < $argnum-1; pos++ )); do
  mycmd="$mycmd${inputargs[$pos]} "
done

# add the rest of your arguments
mycmd="$mycmd-ovc lavc -oac lavc -ffourcc DX50 -o "${inputargs[$argnum-1]}

# and there you have it!
echo "mycmd: $mycmd"


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP