Bash function not working…

JD jd1008 at gmail.com
Tue Jan 8 16:15:31 UTC 2013


On 01/08/2013 08:38 AM, Johnny Rosenberg wrote:
> 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
>
Johnny,
if you want the coma to be your field seperator, then you need
to quote it, like this

awk -F "," '{ print $1 }'

When I did that it worked just fine!





More information about the ubuntu-users mailing list