put this in lambda.sh
#!/usr/bin/env bash
: ${temp_directory=$(mktemp -d "/tmp/demo/example_XXXXXXXXXXXXX")}
: ${filename=$(mktemp "$temp_directory/command_XXXXXXXXXXXX")}
export PATH="$temp_directory:$PATH"
lambda() {
{
echo "#!/usr/bin/env bash"
echo ""
echo "$1"
} > "$filename"
chmod +x "$filename"
echo "$filename"
}
the lambda function generates a valid bash script in a random filename in PATH, and echoes the filename
$ source ./lambda.sh
$ lambda 'echo you said: "$@"'
/tmp/demo/example_L2HH5aaWSeTRi/command_FJyhq4slC0hn
$ cat /tmp/demo/example_L2HH5aaWSeTRi/command_FJyhq4slC0hn
#!/usr/bin/env bash
echo you said: "$@"
you can run the file, of course
$ /tmp/demo/example_L2HH5aaWSeTRi/command_FJyhq4slC0hn hey there
you said: hey there
but you don't really even need to know what the filename is
$ "$(lambda 'echo you said: "$@"')" foo bar baz
you said: foo bar baz