You are not logged in.

#1 2009-06-15 17:50:15

Ranguvar
Member
Registered: 2008-08-12
Posts: 2,549

Why won't this bashrc function work?

I put the following in my bashrc, and resourced it. Then I could "see" the function with bash completion, but running it with "svnrev http://code.autistici.org/svn/fim" failed (-bash: http://code.autistici.org/svn/fim: No such file or directory). If I run the exact code in the function with $1 replaced with the address I just mentioned, it works fine.

function svnrev {
        svn log $1 --limit 1 | sed -e '/^r/!d' -e 's/^r\([0-9]\+\) .*/\1/;q'
}

Any help appreciated smile

Offline

#2 2009-06-15 18:02:47

benob
Member
Registered: 2008-11-11
Posts: 187

Re: Why won't this bashrc function work?

I tried it and it works.
the only thing I removed is the "q" at the end of the sed expression.
maybe you have another typo in your bashrc?

Offline

#3 2009-06-15 23:30:44

Ranguvar
Member
Registered: 2008-08-12
Posts: 2,549

Re: Why won't this bashrc function work?

Nope, still not working even with removing the "q". I don't appear to have any spelling mistakes... hmph.

One other bash / function question, if I may stick it in here? How to I call a function in the middle of another function, explicitly? In other words...

pacmansoabc() { comm -3 <(pacman -Qq) <(pacman -Qqm); } # Give a list of installed packages sorted alphabetically

And then I want to make another function in the same file...

pacmanre() { pacman -S pacmansoabc; } # Reinstall all packages


Obviously, this makes pacman try to install the package "pacmansoabc". If I put "pacmansoabc" in backticks or $(), it complains that there is no such app.


EDIT: It appears that I had previously set svnrev to be an empty alias, and that never went away (apparently functions can't override aliases), so that was my problem. Huh. smile Still looking for info on the problem above smile

Last edited by Ranguvar (2009-06-15 23:53:03)

Offline

#4 2009-06-16 19:19:33

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Why won't this bashrc function work?

[jim@vaio vc3 ~]$ bash
[jim@vaio vc3 ~]$ fun1() { echo "one"; }
[jim@vaio vc3 ~]$ fun2() { echo "two"; echo $(fun1); }
[jim@vaio vc3 ~]$ fun2
two
one
[jim@vaio vc3 ~]$ exit

Are you sure your declaration of pacmansoabc is being sourced prior to, and visibly to, pacmanre? If they're both top-level declarations in your script, and pacmansoabc comes before pacmanre, it should be working.


EDIT: It occurred to me, your first function may be returning a multi-lined result, and then when you pass it to the second function, only the first line is used as an argument to pacman -S. The remaining lines the shell tries to execute as autonomous commands, and fails.

Try piping the results of the first command through xargs, or manipulate them to change the line breaks to spaces, or something like that.

Last edited by Profjim (2009-06-16 19:23:41)

Offline

#5 2009-06-17 01:39:21

Ranguvar
Member
Registered: 2008-08-12
Posts: 2,549

Re: Why won't this bashrc function work?

That's probably it -- simple. Thanks! smile

Offline

Board footer

Powered by FluxBB