How to extract the variables out from “add_shortcode” function?

There are a lot of ays to do the trick, one possible is use a function that use a static variable.

However, before you can be able to get the arguments set in shortcode, the shortcode must be processed…

function foobar_func( $atts = array(), $out = FALSE ){
   static $args = array(
     'foo' => 'default foo',
     'bar' => 'default bar'
   );
   if ( $out ) return $args;
   $args = shortcode_atts( $args, $atts, 'myshortcode' );
   echo 'The value for "foo" argument set in shortcode is: ' . $args['foo'] . '<br>';
   echo 'and the value for "bar" argument set in shortcode is: ' . $args['bar'];
}
add_shortcode( 'myshortcode', 'foobar_func' );

And after the shortcode is processed, you can get all the arguments calling again the function with second arguments set to true:

$shortcode_args = foobar_func( NULL, TRUE );

If called before the shortcode is processed it always return default values.

Another way, probably more reliable, is to trigger a custom action, and use it to pass the shortcode arguments:

function foobar_func( $atts = array() ){
   $defaults = array(
     'foo' => 'default foo',
     'bar' => 'default bar'
   );
   $args = shortcode_atts( $defaults, $atts, 'myshortcode' );
   echo 'The value for "foo" argument set in shortcode is: ' . $args['foo'] . '<br>';
   echo 'and the value for "bar" argument set in shortcode is: ' . $args['bar'];
   // custom action
   do_action( 'myshortcode_processed', $args );
}
add_shortcode( 'myshortcode', 'foobar_func' );

and then hook the action to get arguments and use them:

add_action( 'myshortcode_processed', function( $shortcode_args ) {
  // do whatever you want with $shortcode_args
  var_dump( $shortcode_args );
});