Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How do ${0##*/} and ${0%/*} work?

I have encountered this type of syntax somewhere on the web :

for i in *.avi
    ffmpeg -i "$i" "${i%.avi}.mp4"

how does this "${i%.avi}.mp4" and how can I use it ?

share|improve this question

marked as duplicate by jasonwryan, Gilles, Renan, warl0ck, rahmu Jan 13 '13 at 2:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 3 down vote accepted

This is known as a parameter expansion. Everything to the right of .avi is removed, and .mp4 is concatenated onto the result.

If $i is "foo.avi", the result would be "foo.mp4". BashFAQ 73 has some good examples of other ways you can use parameter expansions for string manipulation.

share|improve this answer
I tried to edit your 2nd mp3 to mp4, but an edit for a single character is not allowed. – ott-- Jan 12 '13 at 18:50
@ott - Corrected, thanks. – jordanm Jan 12 '13 at 22:21

It will remove the suffix .avi from $i (if present) and then concatenate the result with .mp4.

This is called parameter expansion.

The standard ones are described here: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02

Your shell may or may not implement more of those, but if it does, using them will not guarantee portability.

share|improve this answer

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