Skip to main content
added 785 characters in body
Source Link
Ole Tange
  • 37.6k
  • 34
  • 119
  • 228

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?

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?

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?

Source Link
Ole Tange
  • 37.6k
  • 34
  • 119
  • 228

Accessing fish functions from perl

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?