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?

1
  • sorry about dupe, did not see those answers Commented Aug 31, 2017 at 19:23

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.