1

All I want to do is write and export a shell function without:

1) opening a file
2) editing it
3) saving it
4) running it

I'm aware of the implications... Something like:

$ afunc () { echo "i am awesome" } && export -f afunc

When i call afunc it will print "i am awesome" but if i try to do that I get this situation

$ afunc () { echo "aaa" }
>

Anyway way i can do this dynamically from stdin or something?

niken
  • 2,499
  • 3
  • 33
  • 56

1 Answers1

2

This isn't a problem with being inside/outside a script, but a problem in how you're compressing your definition down to a one-liner: You need (but are not including) a semicolon before the closing brace.

The following works:

afunc () { echo "i am awesome"; } && export -f afunc
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441