Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I want to invoke shell function in string. Here is my use case:

function envfoo() {
    env ENV_FOO=foo $@
}
function envbar() {
    env ENV_BAR=bar $@
}

$ envfoo env |egrep ENV_
ENV_FOO=foo
$ envbar env |egrep ENV_
ENV_BAR=bar
$ envfoo envbar env |egrep ENV_
env: envbar: No such file or directory
# expected result: ENV_FOO=foo and ENV_BAR=bar lines

Here I want envfoo to execute envbar shell function. How can I do it?

Say that is opposite of command which ignores shell function and finds real command.


Maybe I gave a wrong example. I want to combine multiple shell functions like actual executables. A real case goes like this:

function be() {
    bundle exec $@
}

function envstg() {
    env RAILS_ENV=staging $@
}

$ be rails server
# launches Rails server

$ envstg be rails server
env: be: No such file or directory

Here be isn't expanded into bundle exec. How can I expand them?

share|improve this question
1  
Why don't use (envbar && envfoo) | grep ENV_ ? –  cuonglm Sep 22 '14 at 3:52
    
Maybe I gave a wrong example. –  knagano Sep 22 '14 at 9:39

1 Answer 1

I don't know why you have the env command there, but it works fine if you remove it:

$ function be() {
>     echo "$@"
> }

$ function envstg() {
>     RAILS_ENV=staging "$@"
> }
$ be rails server
rails server
$ envstg be rails server
rails server
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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