echo x - returns: x: command not found

I have been experiencing this problem intermittantly, I thought the problem was '/bin/sh -> /bin/dash' but I changed that to bash and the problem persists.

I am writing functions to be included in user's '.bash_profile' through source or '.' filename a quick example of the problem is illustrated by this snippet of pseudo code.

function wrapper()
{
	function worker()
	{
		VAR="DEBUG TEXT "$(( $COUNT + 1))
		echo $VAR
	}

	# test for a param first
	# run param
	$(eval $1)
}

I would then source this file and run 'wrapper worker'
the result is:

DEBUG: command not found

Does anyone know what causes this? I can post the actual script. I thought a generic example may do the trick.

Thank you,
Brian

The trouble is with

$(eval $1)

the $(...) executes the output of the function which is DEBUG TEXT n

1 Like

What do you want the failing line to do?

@ Scrutinizer, Thank you.
I changed the syntax to:

function wrapper()
{

    function worker()
    {

        VAR="DEBUG TEXT "$(( $COUNT + 1))
        echo $VAR

    }

    # test for a param first
    # run param
    $1

}

And the problem is solved. Is there a better way I wonder?