In bash I can do:
foo() { echo bar; }
export -f foo
perl -e 'system "bash -c foo"'
I can also access the function definition:
perl -e 'print "foo".$ENV{"BASH_FUNC_foo%%"}'
How do I do the same in fish
?
Edit:
With this I can get the function definition:
functions -n | perl -pe 's/,/\n/g' | while read d; functions $d; end
If I can put that in an enviroment variable accessible from Perl, I ought to be able to execute that before executing the command. So similar to:
setenv funcdefs (functions -n | perl -pe 's/,/\n/g' | while read d; functions $d; end)
perl -e 'system($ENV{"funcdefs"},"foo")'
But it seems setting funcdefs
ignores the newlines: $ENV{"funcdefs"} is one horribly long line.
The odd part is that it seems fish
does support environment variables containing newlines:
setenv newline 'foo
bar'
echo "$newline"
Can I encourage fish
to put the output from the command into a variable, but keeping the newlines?
fish
disable word splitting by default.setenv quux (echo foo;echo bar); echo "$quux"
. It works beautifully in Bash:quux=$(echo foo;echo bar); echo "$quux"