shortcode to display post by category entered by user without plugin

Try the below code. I think it could help you.

add_shortcode( 'knowledge_sharing', 'cat_post' );

function cat_post($atts){

    // attributes for shortcode
   if (isset($atts['cat'])) {$cats = $atts['cat'];} else {return;}
   if (isset($atts['posts_per_page'])) {$posts_per_page = $atts['posts_per_page'];} else {$posts_per_page = -1;}

   // get the category posts
   $category = get_category_by_slug($cat);
   if (!is_object($category)) {return;}
   $args = array(
        'cat' => $category->term_id,
        'posts_per_page' => $posts_per_page,
        'post_type' => 'knowledgeSharingDocs',
        'order'  => 'DESC'
   );
   $posts = get_posts($args);

   // create the list output
   if (count($posts) > 0) {
       foreach ($posts as $post) {
           $link = get_permalink($post->ID);
           $title = $post->post_title;
           $image = get_the_post_thumbnail($post->ID, 'thumbnail');
           $output .= '<div id="postrow-'.$post->ID.'" class="postrow">';
           $output .= '<a class="postlink" href="'.$link.'">'.$image;
           $output .= '<h5 class="posttitle">'.$title.'</h5></a></div>';
       }
   return $output;
}

shortcode: [knowledge_sharing cat="pant" posts_per_page="5"]