Re: Bash function not working…

Tom H tomh0665 at gmail.com
Tue Jan 8 16:35:15 UTC 2013


On Tue, Jan 8, 2013 at 11:04 AM, JD <jd1008 at gmail.com> wrote:
> 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?
>
> For starters, you have a coma after -F
> bad syntax.
> But I tried it without that coma (interactively)
> and it kills the shell.

Either
-F ","
or
-F,




More information about the ubuntu-users mailing list