Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm attempting to write a script for use with HandbrakeCli to convert .mkv-files to XBOX 360 compatible mp4-files.

#!/bin/bash
for f in "$@"
do
    echo "$f"
    HandbrakeCli -i "$f" -o ~/Movies/Handbrake/"${f%.*}.mp4" --preset "Normal" --mixdown "stereo" --subtitle "1" --width 720 --keep-display-aspect
done

The problem is that the destination filename (according to output from HandbrakeCli) includes the full path to the input file. Naturally I'm only interested in the filename without extension since I add .mp4.

I'm not used to shell scripting so help is very much appreciated!

share|improve this question
1  
Also see this discussion of this question on stackoverflow: stackoverflow.com/questions/965053/… –  guenter Oct 3 '11 at 11:11
add comment

2 Answers

up vote 3 down vote accepted

First remove the path:

outf=${f##*/}

Then change the extension:

outf=${outf%.*}.mp4

(Not necessarily in that order, of course.)

share|improve this answer
add comment

Since you know the extension of your input file, you can say

new=~/Movies/Handbrake/"$(basename "$f" .mkv)".mp4
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.