Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # so anyway, output from the echo statement is sent to the terminal. The operands < and >
- # allows you to change where it is going.
- # default redirection
- # 0 stdin -- standard input
- # 1 stdout -- standard output, non-error output
- # 2 stderr -- standard output for error messages.
- # had not used the exec statement before, the concept of the exec was
- # readily apparent to me.
- # of course, I ripped this off. Turns out you want to preserve where input stream 0 is
- # coming from. The hack moves input stream 0 to input stream 6. Pick any number
- # that is allowed.
- # save standard input in file descriptor 6
- exec 6<&0
- # now we say where we want input stream 0 to come from.
- # bash has an unknown to me number of commands that read from input stream 0
- # via redirection we can change were stream 0 is coming from.
- # redirect standard input to be from the passed file
- exec 0<${1}
- count=0
- while read fileName
- do {
- # bash syntax is bizarre.
- # The (( )) says it's a math expression
- (( count++ ))
- echo
- echo "${count}: ${fileName}"
- # Pick output file name.
- baseName="${fileName##*/}"
- # a directory name needs to have a / in it.
- # wild stuff
- # see: http://stackoverflow.com/questions/229551/string-contains-in-bash by Adam Bellaire
- if [[ ${fileName} == *"/"* ]] ; then
- echo "It's there!";
- directoryName="${fileName%/*}/"
- else
- directoryName=""
- fi
- # possible extension
- # Why didn't I use the wild stuff? Because I copied the code I wrote before.
- extension="${baseName##*.}"
- # Was an extension found?
- if [ "${extension}" != "${baseName}" ] ; then
- # extension found, since a period was in the data
- name="${baseName%.*}"
- else
- name="${baseName}"
- fi
- echo "directoryName is '${directoryName}'"
- echo "baseName is '${baseName}'"
- echo "extension is '${extension}'"
- # what we all have been waiting for.
- echo "ffmpeg -i" "${fileName}" "${directoryName}${name}.ext"
- }
- done
- # put the input streams back to where they were before.
- # Nice, but when the script quits they will all be put back to where they were.
- # Of course, I copied this stuff. Syntax isn't the obvious.
- # close input. May not need. My innovation. Seems nice.
- exec 0<&-
- # restore file descriptor 0 should be standard in
- exec 0<&6
- # close file descriptor 6 for reuse.
- exec 6<&-
- echo
- echo "Total lines were ${count}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement