Difference between revisions of "Loops"

From Steak Wiki
Jump to navigationJump to search
Line 40: Line 40:
 
some program that stalls goes here;
 
some program that stalls goes here;
 
done
 
done
 
+
</pre>
 
this will stop at the program, if it doesn't immediately complete
 
this will stop at the program, if it doesn't immediately complete
 
so do this:
 
so do this:
Line 48: Line 48:
 
which will exit script.
 
which will exit script.
 
you can hold ctrl and depress \
 
you can hold ctrl and depress \
</pre>
+
 
 
What is CTRL - \?
 
What is CTRL - \?
 
https://en.wikipedia.org/wiki/Signal_(IPC)
 
https://en.wikipedia.org/wiki/Signal_(IPC)

Revision as of 05:01, 28 October 2020

This is a basic (bash) loop to operate on files.

Examples are given for 7z and video conversion.

#!/bin/bash -x
#for i in *.webm;
        for i in *.7z
 do name=`echo $i | cut -d'.' -f1`;
 echo $name;

#for h264
# ffmpeg -i $i -s 1280x720 -c:a copy $name.mp4;

#for webm

#-map_metadata -1 is to remove metadata, at least try to remove some. (need to verify)
#ffmpeg -i $i -map_metadata -1 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis $name.webm
 7z e -o"$name" ./"$i" 
done

Basically, trim off extension of i, put into name. Use both for extractions/conversion.

Batch Edit Photos

#!/bin/bash
for i in *.JPG
do
#delete exif data
mogrify -strip $i
#test convert size in gimp first to get ratio right
convert -resize 1080x810 $i ~/Desktop/photofolder/$i
done

Interactive Range Loop

#!/bin/bash
for i in {1..254}; 
do 
some program that stalls goes here;
done

this will stop at the program, if it doesn't immediately complete so do this: ctrl - \

that will skip to the next range loop (i increments). note its not ctrl - c which will exit script. you can hold ctrl and depress \

What is CTRL - \? https://en.wikipedia.org/wiki/Signal_(IPC) One of the other options besides ctrl - c.