In my ~/.bashrc, I have a function:
function sayHi() {
echo "hi, $@"
}
and in Ruby I want to:
`sayHi "friend"`
however, sayHi is "not found" in whatever context ruby runs exec or system.
How could I get Ruby to use functions in my .bashrc?
Your .bashrc is only run for interactive shells. When you execute a command using backquotes in Ruby, it does not execute the command in an interactive shell.
You can force an interactive shell by running bash -i. For example, to run your command under an interactive shell, use:
`bash -ic 'sayHi "friend"'`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With