Bash function not working…

Johnny Rosenberg gurus.knugum at gmail.com
Tue Jan 8 15:38:09 UTC 2013


I defined the following function in .bash-functions (which is called
from .bashrc):

speltid () {
ffmpeg -i $1 2>&1 | \
grep Duration | \
awk -F , '{print $1}' | \
sed 's/^.*Duration/Speltid/' | \
sed 's/\./,/'
}


I know the function could have been made much faster, shorter and so
on (for example I think awk could be replaced by some less overkill
feature and sed could be done in one step or I could probably use bash
features only), but that's not what this question is about. I just
want to know why this one, exactly this one, doesn't work (for some
reason people always feel tempted to answer questions that were never
asked, which can be enlightening sometimes and annoying other times…).

Anyway, what I want to happen is this, an example:
$ speltid Så\ kan\ det\ gå.mp4
Speltid: 00:03:09,10
$

(”Speltid” means ”Playing time” or ”Duration” in Swedish)

This is what actually happens:
$ speltid Så\ kan\ det\ gå.mp4
$

If I try the same thing, not using the function, this is what happens:
$ speltid Så\ kan\ det\ gå.mp4
$ ffmpeg -i Så\ kan\ det\ gå.mp4 2>&1 | grep Duration | awk -F ,
'{print $1}' | sed 's/^.*Duration/Speltid/' | sed 's/\./,/'
Speltid: 00:03:09,10
$

That means that the command works as expected, but not in a function
for some reason. What am I missing here?


Johnny Rosenberg




More information about the ubuntu-users mailing list