Shortcode won’t execute

You’re using your shortcode function to directly output something (using echo). Shortcodes are supposed to return the desired output rather than echo it directly. You could use output buffering to “catch” anything that’s outputted (for example, via echo) in an output buffer instead of directly outputting it, and retrieve the content of the buffer afterwards.

This would yield an implementation like this:

function wpse149825_my_shortcode( $atts, $content = NULL ) {
    // Turn on output buffering, which sends output from "echo" to a "buffer" instead of directly outputting it
    ob_start();

    // Output shortcode content
    echo 'Shortcode content';

    // Get buffer contents
    $contents = ob_get_clean();

    // Return shortcode content
    return $contents; 
}

add_shortcode( 'my_shortcode', 'wpse149825_my_shortcode' );

tech