The error occurs because my_test is defined as a shell function in your current shell session, but when you run bash test.sh, it starts a new shell process where my_test is not defined.
Why it fails:
echo my_test > test.sh writes the literal string my_test to test.sh.
When bash test.sh runs, it tries to execute my_test as a command, but it doesn't exist in the new shell.
How to fix it without defining my_test in test.sh:
You need to export the function so it's available in the subshell. Use the export -f command:
This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.