Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert this Windows command to UNIX

Status
Not open for further replies.

tehon3299

Programmer
Aug 30, 2006
4
US
Hey all,

I'm trying to convert this Windows command to work on my Linux box. Anyone help?

command:
for %i in (*.avi) do ffmpeg -i %i -f mjpeg -t 0.001 -ss 5 -y %~ni.tbn

Thanks!
 
I have no idea what "ffmpeg" and "mjpeg" do, so the commands and options might not work, but to just convert your script to a UNIX equiv, it might be something like this:

for i in `ls *.avi`
do
ffmpeg -i $i -f mjpeg -t 0.001 -ss 5 -y $i.tbn
done




"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
Thanks man! Works like a charm if I put it in a file and run it. Can I run this from a prompt without having to put it in a file?
 
Yea if you enter each line individually. Why would you want to do that anyway? Just make it a script and add it to your path.
 
I want to do this because I have to do this to multiple directories. Could I make this script grab the current directory somehow? So I can 'cd' to the directory I want and then run the command?
 
coffeysm said:
as long as the location is in your PATH.

meaning: as long as the script you made (make) is in a directory which is listed in the $PATH variable.

echo $HOME # home dir
echo $PATH # search path

if you see a directory which is your home_dir or something derived thereof /home/username/bin e.g. Put the script in there and you can run it from wherever you are.

HTH,

p5wizard
 
Could I make this script grab the current directory somehow?

Code:
DIR=$1
if [ "$DIR" != "" ]
   then
   cd $DIR
fi
for i in `ls *.avi`
do
  ffmpeg -i $i -f mjpeg -t 0.001 -ss 5 -y $i.tbn
done

Now just run your script with the destination directory as the first argument. You can expand on this to preset a list of directories like so:

Code:
for j in `cat $HOME/dlist`
do
  cd $j
  for i in `ls *.avi`
  do
    ffmpeg -i $i -f mjpeg -t 0.001 -ss 5 -y $i.tbn
  done
done

Note that this is a pretty basic outline, and has no provisions to make sure $HOME/dlist exists, or that the directories contained in $HOME/dlist are valid. As written, the directory names listed in $HOME/dlist would need to be full pathnames.

"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
Instead of
Code:
for i in `ls *.avi`,

which is errorprone in case of blanks in filenames (they're kind of common sense in windows), I suggest:
Code:
for i in *.avi

Perhaps that's only true for bash, so test it out.

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top